Home  >  Article  >  Web Front-end  >  After selecting the specified number, the checkbox is unselectable (grayed) javascript code_javascript skills

After selecting the specified number, the checkbox is unselectable (grayed) javascript code_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:52:011400browse

You can see the effect after selecting 3

Other Western Food
[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<script> function disableCheckBox() { var obj=document.getElementsByTagName("input") for(var i=0;i<obj.length;i++) { if ( !obj[i].checked ) obj[i].disabled = true; } } function ableCheckBox() { var obj=document.getElementsByTagName("input") for(var i=0;i<obj.length;i++) obj[i].disabled = false; } function check() { var obj=document.getElementsByTagName("input") var sun=0; for(var i=0;i<obj.length;i++) { if(obj[i].type=="checkbox" && obj[i].checked) sun++; if( sun< 3 ) { ableCheckBox(); //break; } else if(sun == 3 ) { disableCheckBox(); event.srcElement.checked=true; break; } else if(sun > 3 ) { event.srcElement.checked=false; break; } } } </script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn