This article mainly shares with you a js sample code that implements a check box that can only select one item. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.
The example is as follows:
<!DOCTYPE HTML> <html> <head> <title></title> </head> <body> <ul> <li><input type="checkbox" name="ss" onclick="choose(this)">1</li> <li><input type="checkbox" name="ss" onclick="choose(this)">2</li> <li><input type="checkbox" name="ss" onclick="choose(this)">3</li> <li><input type="checkbox" name="ss" onclick="choose(this)">4</li> <li><input type="checkbox" name="ss" onclick="choose(this)">5</li> </ul> <script language="JavaScript"> function choose(obj){ var ss= document.getElementsByName("ss"); for (var i = 0; i < ss.length; i++) { ss[i].checked = false; } obj.checked = true; } </script> </body> </html>
Have you learned it? Hurry up and try it out.
How to make the checkbox only select one item_javascript skills
jquery handles whether the checkbox checkbox is selected example code sharing
The above is the detailed content of Detailed explanation of how to implement a checkbox with js that can only select one item. For more information, please follow other related articles on the PHP Chinese website!