当我点击一个复选框时,为什么没有添加选中的属性?你可以在这里看到代码http://jsfiddle.net/FCrSg/
发布于 2011-02-03 10:05:44
你想做什么?看看是否检查过了?
$('.user_roles').click(function(){
console.log( $(this).is(':checked'));
});http://jsfiddle.net/petersendidit/FCrSg/1/
发布于 2011-02-03 10:06:02
HTML attribute checked的意思是:在页面加载时默认选中。单击复选框时,此选项不会更改。
<input type="checkbox" checked="checked"> <!-- The HTML attribute -->checkbox的DOM属性 checked实际上是复选框的当前状态,可以是true/false。这将在单击复选框时更改,但在检查HTML时不可见。
$('input:check')[0].checked == true;
// Whether or not the checkbox is currently checked发布于 2011-02-03 10:10:10
如果您希望它出现在控制台中显示的元素上,请使用本机setAttribute()方法。
示例: http://jsfiddle.net/FCrSg/2/
this.setAttribute('checked',this.checked);所以它看起来像这样:
$('.user_roles').click(function(){
this.setAttribute('checked',this.checked);
console.log( $(this) );
});那么控制台应该会给你:
<input class="user_roles" type="checkbox" checked="true">尽管您通常不需要像这样设置属性。通常情况下,属性就足够了。
https://stackoverflow.com/questions/4882000
复制相似问题