jQuery - 无法从复选框中删除选中的属性
jQuery - Unable to remove checked attribute from checkboxes
我生成了一个表单,其中包含对与我的数据库通信的 PHP 页面的 Ajax 请求的答复。
当我点击 submit
按钮时,我通过 jQuery 收集简单数组中不同表单输入(文本、复选框、文本区域...)的内容以发送它们返回数据库。
现在我想在提交后重置form
。
我没有使用 myForm.reset()
来清除所有内容(它什么也没做),即使使用了我在 Whosebug 和互联网上找到的所有方法。所以我决定自己编写清晰的过程。
主要问题:我收集选中复选框的值:
var complement0=[];
complement0.push($("input[name=foo]:checked").map(function() {
return this.value;
}).get());
然后尝试取消选中复选框。以下是我尝试过但没有成功的方法:
$("input[name=foo]:checked").each(function() {
$(this).removeAttr('checked');
});
$("input[name=foo]:checked").map(function() {
return this;
}).removeAttr('checked');
$("input[name=prsFmtLng]:checked").attr('checked',false);
$("input[name=prsFmtLng]:checked").removeAttr('checked');
因为当其他人谈论这个时看起来很简单:要么我不明白我在做什么,要么我只是错过了什么。
欢迎任何帮助。
答案:
$("input[name=foo]:checked").map(function() {
$(this).prop('checked',false);
});
checked
是一个 属性.
使用:
.prop('checked',false);
;)
我生成了一个表单,其中包含对与我的数据库通信的 PHP 页面的 Ajax 请求的答复。
当我点击 submit
按钮时,我通过 jQuery 收集简单数组中不同表单输入(文本、复选框、文本区域...)的内容以发送它们返回数据库。
现在我想在提交后重置form
。
我没有使用 myForm.reset()
来清除所有内容(它什么也没做),即使使用了我在 Whosebug 和互联网上找到的所有方法。所以我决定自己编写清晰的过程。
主要问题:我收集选中复选框的值:
var complement0=[];
complement0.push($("input[name=foo]:checked").map(function() {
return this.value;
}).get());
然后尝试取消选中复选框。以下是我尝试过但没有成功的方法:
$("input[name=foo]:checked").each(function() {
$(this).removeAttr('checked');
});
$("input[name=foo]:checked").map(function() {
return this;
}).removeAttr('checked');
$("input[name=prsFmtLng]:checked").attr('checked',false);
$("input[name=prsFmtLng]:checked").removeAttr('checked');
因为当其他人谈论这个时看起来很简单:要么我不明白我在做什么,要么我只是错过了什么。
欢迎任何帮助。
答案:
$("input[name=foo]:checked").map(function() {
$(this).prop('checked',false);
});
checked
是一个 属性.
使用:
.prop('checked',false);
;)