我对 ajax/javascript 很陌生,所以我会尽力解释我的问题。这是我到目前为止所拥有的:
$(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 {
}
}
});
});
});
每次选中复选框时,ajax 都会将数据传递到服务器上。以下是在从开发者控制台获取的数据表单中检查了一些复选框值后的一些复选框值的示例:
最佳答案
您可以尝试以下代码:
filterCheckboxes.push($(this).prop("name") + "=" + $(this).val());
关于javascript - 在 ASP.NET 中使用 javascript 进行检查时,如何传递复选框的值和相应的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27711392/