日期:2014-05-16 浏览次数:20411 次
<!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" /> <title>无标题文档</title> <script type="text/javascript"> window.onload = function() { var obj = document.getElementsByName('bm[]'); var jb = document.getElementById('jb'); jb.onchange = function() { //下拉列表选项改变时清除所有复选框的选择状态 for (var i = 0; i < obj.length; i ++) obj[i].checked = false; } for (var i = 0; i < obj.length; i ++) { obj[i].onclick = function() { if (jb.value == 2 || jb.value == 3) { var counter = 0; for (var j = 0; j < obj.length; j ++) if (obj[j].checked) counter ++; if (counter > 1) { alert('中层和员工只能选一个'); return false; } } } } } </script> </head> <body> <select id="jb"> <option value="1">高层</option> <option value="2">中层</option> <option value="3">员工</option> </select> 选择1<input type="checkbox" name="bm[]" value="我" /> 选择2<input type="checkbox" name="bm[]" value="我" /> </body> </html>