限选择

来源:互联网 发布:淘宝小二帮忙上活动 编辑:程序博客网 时间:2024/04/28 10:30

<script type="text/javascript">
var i=1;
var MAX=4;
function ls(obj){
if(obj.checked){
if(i<=MAX){
i++;
}
else{
obj.checked=false;
alert('你最多只能选'+MAX+'项');
}
}
else{
i--;
}
}
</script>
<form action="#Success" name="myform" method="post">
兴趣爱好:<br />
网络<input type="checkbox" name="like" value="网络" onclick="ls(this)" /><br />
娱乐<input type="checkbox" name="like" value="娱乐" onclick="ls(this)"/><br />
阅读<input type="checkbox" name="like" value="阅读" onclick="ls(this)"/><br />
编程<input type="checkbox" name="like" value="编程" onclick="ls(this)"/><br />
旅游<input type="checkbox" name="like" value="旅游" onclick="ls(this)"/><br />
烹饪<input type="checkbox" name="like" value="烹饪" onclick="ls(this)"/><br />
音乐<input type="checkbox" name="like" value="音乐" onclick="ls(this)"/>
</form>
</body>

原创粉丝点击