[英]How can I pass the value and corresponding name of a checkbox when checked using javascript in ASP.NET?
I'm very new to ajax/javascript so I will try my best to explain my problem. 我对ajax / javascript非常陌生,因此我将尽力解释我的问题。 Here's what I have so far:
这是我到目前为止的内容:
$(function () {
$("#chkFilter").on("click", "input", function (e)
{
var filterCheckboxes = new Array();
$("#chkFilter").find("input:checked").each(function () {
//console.log($(this).val()); //works fine
filterCheckboxes.push($(this).val());
console.log($(this).val());
//var filterCheckboxes = new Array();
//for (var i = 0; i < e.length; i++) {
// if (e[i].checked)
// filterCheckboxes.push(e[i].value);
//}
});
console.log("calling ajax");
$.ajax({
url: "/tools/oppy/Default.aspx",
type: "post",
dataType: "json",
data: { UpdateQuery: filterCheckboxes }, // using the parameter name
success: function (result) {
if (result.success) {
}
else {
}
}
});
});
});
Every time a checkbox is checked, ajax passes the data onto the server. 每次选中复选框时,ajax都会将数据传递到服务器上。 Here is an example of some checkbox values after a few have been checked in the data form obtained from the Developer's Console:
这是在从开发者控制台获得的数据表单中选中一些复选框值后的一些复选框值的示例:
您可以尝试以下代码:
filterCheckboxes.push($(this).prop("name") + "=" + $(this).val());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.