我在 Razor View 引擎上有一个复选框:
@Html.CheckBoxFor(model => model.Attempt, new { id = "Attempt" })
我想在复选框上的每个选中/取消选中时发出 ajax 请求。所以,我使用了 javascript,
$(document).ready(function () {
// Some other functions here
$('#Attempt input:checkbox').change(function () {
$.ajax({
url: '@Url.Action("Select", "Test")',
type: 'POST',
data: { attempt: true }
});
})
});
但它根本不起作用。根本没有发送任何请求。我错过了什么?
还有,如何根据check/uncheck映射数据attempt
true or false?
最佳答案
我不知道为什么它不起作用,但我稍作修改使其起作用。
$('#Attempt').change(function () {
if ($('#Attempt').is(':checked')) {
$.ajax({
url: '@Url.Action("Select","Test")',
data: { isLocked: true },
type: 'POST',
dataType: "json"
});
}
});
关于javascript - 复选框 ajax 请求选中/取消选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11650287/