Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 18:52:01
Original
1427 people have browsed it

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>
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template