>  기사  >  웹 프론트엔드  >  입력:체크박스 다중 선택 상자는 라디오와 동일한 단일 선택 효과를 얻습니다.

입력:체크박스 다중 선택 상자는 라디오와 동일한 단일 선택 효과를 얻습니다.

高洛峰
高洛峰원래의
2018-05-17 17:04:282659검색

최근에 작은 문제가 발생했습니다. 즉, 단일 선택 라디오를 사용할 때 하나를 선택한 후에는 더 이상 아무것도 선택할 수 없습니다. 즉, 선택한 후 취소 기능이 없다는 것을 알게 됩니다. 강력한 체크박스를 생각했는데 어떻게 하면 단일 선택으로 바꿀 수 있을까요? 제가 직접 작성한 작은 프로그램은 단 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"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<script src="js/jquery-1.8.3.min.js" type="text/javascript" language="javascript"></script> 
<title>无标题文档</title> 
<script type="text/javascript"> 
$(function(){ 
$(":checkbox").click(function(){ 
if($(this).attr("checked")!=undefined) 
{ 
$(this).siblings().attr("checked",false); 
$(this).attr("checked",true); 
} 
}); 
}); 
</script> 
<style> 
span,input{float:left;} 
input{ width:14px; height:14px;} 
span{ margin-right:20px;} 
</style> 
</head> 

<body> 
<p> 
<input type="checkbox" /><span>1</span> 
<input type="checkbox" /><span>2</span> 
<input type="checkbox" /><span>3</span> 
<input type="checkbox" /><span>4</span> 
<input type="checkbox" /><span>5</span> 
<input type="checkbox" /><span>6</span> 
<input type="text" /><span>7</span> 
</p> 
</body> 
</html>

추가 입력: 라디오와 동일한 단일 선택 효과를 얻기 위한 확인란 다중 선택 상자 관련 기사를 보려면 PHP 중국어 웹사이트에 주목하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.