读书人

Jquery令checkbox替单选

发布时间: 2012-11-22 00:16:41 作者: rapoo

Jquery令checkbox为单选

Jquery令checkbox为单选<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//第一种方法
??? $(".c").click(function(){
??????? $(this).siblings().attr('checked',false);
??? });
//第二种方法
??? $(".c1").click(function(){
?? ?$('.c1').attr('checked',false);
?? ?$(this).attr('checked',true);
??? });
});
function f1(){
$('#fc').attr('checked',true);
}
</script>
</head>
<body>
第一种方法<br/>
<input type="checkbox" id="fc" value="hi" value="点我" onclick="f1();"/> <br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>

第二种方法<br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
</body>
</html>

读书人网 >Web前端

热点推荐