checkbox的第三种状态--不确定状态

视觉上,checkbox有三种状态:checked、unchecked、indeterminate(不确定的)。看起来就像这样子:

对于indeterminate状态的checkbox需要注意的是:你无法在HTML中设置checkbox的状态为indeterminate。因为HTML中没有indeterminate这个属性,你可以通过Javascript脚本来设置它

1
2
var checkbox = document.getElementById("reyo-checkbox");
checkbox.indeterminate = true;

 或者通过jQuery来设置

1
$("#reyo-checkbox").prop("indeterminate", true); // prop is jQuery 1.6+<br><br>
$("#reyo-checkbox").attr("indeterminate", true);
$("#reyo-checkbox").prop("indeterminate", true);
两种都可以,不过新版jquery推荐第二种,两个在其他方面都差不多,我发现的唯一不同就是在checkbox上的时候,需要用prop,不然IE浏览器会不兼容
posted @ 2019-01-29 16:18  佳明兄  阅读(450)  评论(0编辑  收藏  举报

内容仅为参考使用,不保证内容的正确性,通过使用本博客内容随之而来的风险与作者无关。内容如有侵权,请通知删除!