我有一些代码在最新版本的 chrome (32.0.1700.107) 中损坏了。 jQuery 版本是 1.10.1。这段代码去年一直在其他浏览器中运行。它在 IE8 中可以正常工作。代码的关键部分如下 -
var stateWideCb = $('.showStatewide input');
stateWideCb.change(function () {
var b = $(this).is(':checked');
$('.showRegion input').attr('checked', b);
});
发生的情况是,在前两次单击 Master 复选框后,代码停止工作。
最佳答案
改变:
.attr('checked', b);
到
.prop('checked', b);
To retrieve and change DOM properties such as the checked, selected, or disabled state of form elements, use the .prop() method.
关于javascript - 无法使用 jQuery 在 Chrome 中将复选框设置为已选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21864916/