<script>
function check(obj)
{
for(i=0;i<document.form1.r1.length;i++)
if(document.form1.r1[i]==obj)
{
j=document.form1.r1[i].checked?"未":"";
alert("第"+(i+1)+"个checkbox,原来状态"+j+"被选中");}
}
</script>
<form name=form1>
<input type=checkbox name=r1 value=1 onclick=check(this)>
<input type=checkbox name=r1 value=2 onclick=check(this)>
<input type=checkbox name=r1 value=3 onclick=check(this)>
</form>

解决方案 »

  1.   

    <form name=form1 onClick="aa()">
    <input type=checkbox name=r1 value=1>
    <input type=checkbox name=r1 value=2>
    <input type=checkbox name=r1 value=3>
    </form>
    <SCRIPT LANGUAGE="JavaScript">
    function aa() {
    obj=event.srcElement;
    if(obj.checked)
    alert(obj.value + " 选了");
    else
    alert(obj.value + " 没选")
    }
    </SCRIPT>
      

  2.   

    那就在id中标识序号
    <script>
    function check(obj)
    {
    j=obj.checked?"未":"";
    alert("第"+obj.id.substr(obj.id.length-1)+"个checkbox,原来状态"+j+"被选中");
    }
    </script>
    <form name=form1>
    <input type=checkbox name=r1 value=1 id=check1 onclick=check(this)>
    <input type=checkbox name=r1 value=2 id=check2 onclick=check(this)>
    <input type=checkbox name=r1 value=3 id=check3 onclick=check(this)>
    </form>
      

  3.   

    //*************************************** 
    //* 功能:得到单选框组中用户选择项的下标 
    //* 参数:单选框对象 
    //* 输出:下标,没有选择则返回-1 
    //* 作者:阿福,[email protected] 
    //* 时间:2002-10-30 11:30 
    //*************************************** 
    function getCheckedRadio(obj) 

        var item; 
        var len=obj.length; 
        for(item=0;item<len;item++) 
        { 
            if(obj[item].checked) 
            { 
                return item; 
            } 
        } 
        return -1;