js 实现复选框只能选择一项的示例代码
网络 2018-02-02 1195
实例如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <!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> |