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

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

对于indeterminate状态的checkbox须要注意的是:你没法在HTML中设置checkbox的状态为indeterminate。由于HTML中没有indeterminate这个属性,你能够经过Javascript脚原本设置它jquery

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浏览器会不兼容
相关文章
相关标签/搜索