我有一个asp.net应用程序,其中我必须自定义操作,单击表单的提交按钮:
剧本
<script>
$(function(){
function result(arr, identificateur,Pages) {
var f1 = $('input[name="reception' + arr + '"]').val();
var f2 = $('input[name="client' + arr + '"]').val();
var f3 = $('input[name="cloture' + arr + '"]').val();
var f4 = $('input[name="tag' + arr + '"]').val();
location = "@Url.Content("/Pages/Index")?identificateur=" + identificateur + "&Pages=" + Pages + "&_reception=" + f1 + "&_cloture=" + f3 + "&_client=" + f2 + "&_tag=" + f4;
}});
</script>
然后,形式为:
<input type="submit" onclick="result(@i.ToString(),@Model[1][i].Id ,"1");" value="Enregistrer"/>
当我单击“提交”按钮时,什么也没有发生,并且我也没有重定向到操作Index
。
此问题的原因是什么?我该如何解决?
编辑
<input type="submit" id="Enregistrer" value="Enregistrer" data-arr="@i.ToString()" data-identificateur="@Model[1][i].Id" />
<script>
$(function () {
$('#Enregistrer').click(function () {
var self = $(this); // This is the submit button
var identificateur = self.data('identificateur');
var arr = self.data('arr');
var f1 = $('input[name="reception' + arr + '"]').val();
var f2 = $('input[name="client' + arr + '"]').val();
var f3 = $('input[name="cloture' + arr + '"]').val();
var f4 = $('input[name="tag' + arr + '"]').val();
document.location.href = "@Url.Content("/Pages/Index")?identificateur=" + identificateur + "&Pages=1&_reception=" + f1 + "&_cloture=" + f3 + "&_client=" + f2 + "&_tag=" + f4;
});
});
</script>
问题:
重定向不起作用
只有在第一个tr
中,我才能达到js
功能
参考方案
我认为我发现了两个错误:
location
应该
location.href
第二,尝试为函数添加javascript:
前缀:
<input type="submit" onclick="javascript:result(@i.ToString(),@Model[1][i].Id ,"1");" value="Enregistrer"/>
甚至更好的是,使用具有html5 data-
属性的兼容的javascript。
<input type="submit" id="Enregistrer" value="Enregistrer" data-reception="@i.ToString()" />
使用以下JavaScript:
$('#Enregistrer').click(function () {
var self = $(this); // This is the submit button
var reception = self.data('reception'); // Get the data from the attributes.
});
asp.net:treeview-显示文本框是否选中? - c#我需要向用户显示字符串列表。用户可以选择多个字符串。如果选择了一组特定的字符串,则每个字符串旁边都会出现一个文本框。我想做的是向用户显示一个TREEVIEW,每个节点都是字符串之一。他们将通过选中复选框来选择所需的每个字符串。问题:如果用户选择特定的复选框,则我需要一个文本框来显示用户的GET输入。问题:如何从用户使用树形视图获取字符串输入? 参考方案 Tr…
ASP.NET Gridview ButtonField onclick触发包含行的onclick事件 - c#我有一个gridview行,当单击该行时必须执行回发操作A,而在该行中单击该行时必须执行回发操作B的按钮字段。问题是,当我单击按钮字段时,会触发event1和event2。下面是代码。protected void gdv_RowCommand(object sender, GridViewCommandEventArgs e) { string arg = …
ASP.NET MVC 5自定义登录,无需脚手架,数据库优先 - c#我对asp.net和mvc还是很陌生,所以我正在努力学习尽可能多的知识...为此,我从头开始编写博客网站,但是我对身份验证和授权有些困惑。由于我倾向于不真正使用任何脚手架的东西,所以我首先要使用数据库,所以不希望asp.net身份为我创建表。我对散列和加盐密码很酷,并对照数据库检查用户,我遇到的麻烦是将用户设置为登录状态并检查他们应该能够访问什么。我真的很想…
asp.net oledbcommand返回所有行 - c#我正在使用Oledbconnection连接到Microsoft Access数据库,并且正在使用OleDbCommand检索一些信息。我在数据库中有一个名为retrieveInfo的查询,该查询检索3行数据。字段中有一些重复项,但是应该是这样。我的数据如下所示: Name Email A [email protected] B [email protected] B C@gmai…
如何在没有for循环的情况下在Javascript中使用Django模板标签 - javascript我想在JavaScript中使用模板变量:我的问题是在javascript代码中使用for循环,for循环之间的所有事情都会重复..但我不想要....下面粘贴了我的代码..有人可以告诉我更好的方法吗这..因为这看起来很丑..这是我的代码: {% block extra_javascript %} <script src="/static/js…