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浏览器会不兼容

猜你喜欢

转载自www.cnblogs.com/DreamSeeker/p/10334599.html