<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function checkchk()
{
var arychk = document.getElementsByTagName('input');
var rs = '';
for (var i=0; i<arychk.length; i++)
{
if (arychk[i].type == "checkbox")
{
if (arychk[i].checked)
{
rs += ',' + arychk[i].value;
arychk[i].disabled = true;
}
}
}
if (rs != '')
{
rs = rs.substring(1);
if (rs.indexOf(',') != -1)
{
alert(rs + " Selected:\nError");
}
}
}
//-->
</SCRIPT>
<form name=frm>
<INPUT TYPE="checkbox" NAME="chk1" value="chk1">chk1
<INPUT TYPE="checkbox" NAME="chk2" value="chk2">chk2
<INPUT TYPE="checkbox" NAME="chk3" value="chk3">chk3
</form>
<button onclick='checkchk()'>监测</button>
<button onclick='window.location.reload()'>复位</button>
</BODY>

解决方案 »

  1.   

    <input type=checkbox name=a value=1>
    <input type=checkbox name=a value=2>
    <input type=checkbox name=a value=3>
    <input type=checkbox name=a value=4>
    <input type=button onclick=get() value=Get>
    <script>
    var chk = document.getElementsByName("a");
    for(var i=0;i<chk.length;i++)
    {
       chk[i].onclick = function() {
           for(var j=0;j<chk.length;j++) chk[j].checked=false;
           this.checked = true;
       }
    }
    function get()
    {
        for(var i=0;i<chk.length;i++) if(chk[i].checked)alert(chk[i].value);
    }
    </script>