[英]How can I pass the value and corresponding name of a checkbox when checked using javascript in ASP.NET?
我對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());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.