扫码关注官方订阅号
我想为页面提供一个全选的功能,于是写了一个jquery.
我在页面运行,元素的checked属性在变化,但是页面就是不渲染效果打钩和不打勾,只有刚载入是页面时执行一次。
学习是最好的投资!
使用prop而非attr
$("#selectAll").on("click",function(){ if($(this).prop("checked")){ $("input[type='checkbox']:not(#selectAll)").prop("checked",true); console.log('true'); } else{ $("input[type='checkbox']:not(#selectAll)").prop("checked",false); console.log('false'); } })
<input type="checkbox" id="selectAll"/> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> $("#selectAll").click(function(){ $("input[type='checkbox']:not(#selectAll)").attr("checked",$(this).attr("checked") == 'checked') })
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
使用prop而非attr