[英]Checking whether checkbox has been unchecked
I am trying to send post requests to the database dependant on whether a checkbox is checked or unchecked I want to add to database or delete from database with the post requests. 我试图将发布请求发送到数据库,具体取决于我是否要使用发布请求将其添加到数据库或从数据库中删除复选框。 I have managed to successfully get the add working via post request but I am unable to get it to delete using the jQuery below:
我已经成功地通过帖子请求成功完成了添加工作,但是我无法使用下面的jQuery将其删除:
$(function () {
$("input:checkbox").change(function () {
var fullURL = document.URL;
var url = fullURL.split('userID=');
var userID = url[1];
var courseID = this.value;
var postData = { 'userId': userID, 'courseID': courseID };
if (!this.checked) {
$.post('/Admin/UnenrolUser/', postData, function (data) {
});
}
if (this.checked) {
$.post('/Admin/EnrolUser/', postData, function (data) {
});
}
});
});
My this.checked if statement seems to be working as expected. 我的this.checked if语句似乎按预期工作。 How can I get the unchecked to work in this context?
我如何才能不受限制地在这种情况下工作?
if (this.checked) {
$.post('/Admin/EnrolUser/', postData, function (data) {
});
} else {
$.post('/Admin/UnenrolUser/', postData, function (data) {
});
}
尝试这个
if(!$(this).is(':checked'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.