최근에 나는 작은 문제를 겪었습니다. 때로는 단일 선택 라디오를 사용할 때, 우리는 하나를 선택할 때 더 이상 선택할 수 없으며, 즉, 선택한 후 취소 함수가 없다는 것을 알게 될 것입니다. 현재 우리는 강력한 확인란을 생각하지만 객관식이므로 어떻게 단일 선택으로 만들 수 있습니까? 효과는 라디오와 동일합니다. 이 신인은 스스로 작은 프로그램을 썼습니다. 코드는 4 줄만으로 매우 간단합니다.
더 이상 고민하지 않고 직접 코드 :
코드 사본은 다음과 같습니다.
<! doctype html public "-// w3c // dtd xhtml 1.0 Transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<헤드>
<meta http-equiv = "content-type"content = "text /html; charset = utf-8" />
<script src = "js/jquery-1.8.3.min.js"type = "text/javaScript"언어 = "javaScript"> </script>
<title> 제목의 문서 </title>
<script type = "text/javaScript">
$ (function () {
$ ( ": checkbox"). 클릭 (function () {
if ($ (this) .attr ( "Checked")! = undefined)
{
$ (this) .siplings (). attr ( "확인", 거짓);
$ (this) .attr ( "Checked", true);
}
});
});
</스크립트>
<스타일>
스팬, 입력 {float : 왼쪽;}
입력 {너비 : 14px; 높이 : 14px;}
스팬 {마진 오른쪽 : 20px;}
</스타일>
</head>
<body>
<div>
<입력 유형 = "CheckBox" /> <span> 1 < /span>
<입력 유형 = "CheckBox" /> <span> 2 < /span>
<입력 유형 = "checkbox" /> <span> 3 < /span>
<입력 유형 = "checkbox" /> <span> 4 < /span>
<입력 유형 = "CheckBox" /> <span> 5 < /span>
<입력 유형 = "CheckBox" /> <span> 6 < /span>
<입력 유형 = "텍스트" /> <span> 7 < /span>
</div>
</body>
</html>