今天做项目是遇到一个问题想实现复选框中单选,但有不想直接使用input的radio,其一难看,其二点了无法返回
所以这样实现了:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>我爱学习</title>
<jsp:include page="../inc.jsp"></jsp:include>
<script>
$(function(){
$('#test').children('input[type=checkbox]').click(function(){
if($(this).is(':checked')){
$(this).attr('checked',true).siblings().attr('checked',false);
alert($(this).val());
}else{
$(this).attr('checked',false).siblings().attr('checked',false);
}
});
});
</script>
</head>
<body>
<div id="test">
<input type="checkbox" value="php" />php
<input type="checkbox" value="html/css" />html/css
<input type="checkbox" value="jquery" />jquery
<input type="checkbox" value="javascript" />javascript
<input type="checkbox" value="mysql" />mysql
</div>
</body>
</html>