script判断复选框是还被选中

<title>JavaScript 获取复选框的值 站长学院 www.pigzz.com</title>

    <script>

    function checkbox()

    {

    var str=document.getElementsByName("box");

    var objarray=str.length;

    var chestr="";

    for (i=0;i<objarray;i++)

    {

    if(str[i].checked == true)

    {

    chestr+=str[i].value+",";

    }

    }

    if(chestr == "")

    {

    alert("请先选择复选框~!");

    }

    else

    {

    alert("复选框的值是:"+chestr);

    }

    }

    </script>

    选择您的拿手技术:

    <input type="checkbox" name="box" id="box1" value="ASP" />ASP

    <input type="checkbox" name="box" id="box2" value="PHP" />PHP

    <input type="checkbox" name="box" id="box3" value="JSP" />JSP

<input type="button" name="button" id="button" onclick="checkbox()" value="提交" />

posted @ 2012-04-12 16:25  天宫之神  阅读(168)  评论(0编辑  收藏  举报