Home > Web Front-end > JS Tutorial > body text

Detailed explanation of how to implement a checkbox with js that can only select one item

小云云
Release: 2018-01-24 09:37:38
Original
3617 people have browsed it

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>
Copy after login

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

Detailed example of jQuery getting the value of a field in the current row selected by the check box_

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!

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