用JavaScript,如何判断CheckBox选中/未选中?具体代码怎么写?谢谢!

解决方案 »

  1.   

     checked属性true和false来判断
      

  2.   


    写代码不好吗?
    思路我也知道,具体写起来就是不管用,我想要的是正确的写法。
    凡是人都知道checked属性
      

  3.   


    <html>
    <head>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title></title>
    <script>
    function show()
    {
    var ch1=document.getElementById("ch1");
    alert(ch1.checked);
    }
    </script>
    </head>
    <body>
    <form>
    <input id="ch1" type="checkbox" name="bike" />I have a bike<br />
    <input type="checkbox" name="car" />I have a car
    </form>
    <input type="button" value="CLICK ME" onclick="show()"/>
    </body>
    </html>
      

  4.   

    参考...<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>TEST</title>
    </head>
    <style type="text/css">
    *{font-family:verdana; font-size:12px;}
    </style>
    <script type="text/javascript">
    function $(id){
    return "string" == typeof(id) ? document.getElementById(id) : id ;
    }function trim(str){
    return str.replace(/^\s|\s$/g,"");
    }function check(){
    var o1=$("chkbox1");
    var o2=$("chkbox2");
    var msg='';
    if(o1.checked) 
    msg = 'box1 选中, 值 = '+ o1.value+'\n';
    else
    msg = 'box1 没选中\n';if(o2.checked) 
    msg += 'box2 选中, 值 = '+ o2.value+'\n';
    else
    msg += 'box2 没选中\n';
    alert(msg);
    }
    </script>
    <body>
    box1:<input name="chkbox1" id="chkbox" type="checkbox" value="OK">OK
    box2:<input name="chkbox2" id="chkbox" type="checkbox" value="NO">NO
    <br><a href="javascript:check();">check </a>
    </body>
    </html>
      

  5.   

    jquery的 供楼主学习!
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    </head>
    <body>
        <input type="checkbox" name="publish" value="人民教育出版社">人民教育出版社
        <input type="checkbox" name="publish" value="北京师范大学出版社">北京师范大学出版社
        <input type="checkbox" name="publish" value="">
    </body>
    </html>
    <script>
        $(function () {
            //跟多选框添加点击事件
            $("input[type='checkbox']").bind("click", function () {
                //如果选中
                if (this.checked == true) {
                    //弹出值
                    alert(this.value);
                }
            });
        });
    </script>
      

  6.   

    <!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>
    </head><body>
    <script>
    function abc(){


    var c=window.document.forms.item(0).childNodes.item(0).checked;
    alert(c)
    }
    function def(){


    var c=window.document.forms.item(0).childNodes.item(1).checked;
    alert(!c)
    }
    </script>
    <form name="abcd" >
    <input type="checkbox" name="a" checked="checked"  onclick="abc()" />
    <input type="checkbox" name="b" onclick="def()"/>
    <input type="button" value="234" onclick="abc()"  />
    </form>
    </body>
    </html>
      

  7.   


      <input type="checkbox" name="love" onclick="c(this)">x
      <input type="checkbox" name="love" onclick="c(this)">y
      <input type="checkbox" name="love" onclick="c(this)">z
      <input type="checkbox" name="love" onclick="c(this)">a
      <input type="checkbox" name="love" onclick="c(this)">b
      <input type="checkbox" name="love" onclick="c(this)">c
      <input type="checkbox" name="love" onclick="c(this)">d <script>
    function c(o){
    if(o.checked==true){
    o.disabled = true;
    }
    }
     </script>
      

  8.   

    strbScript.Append("document.getElementById('").Append(Me.txtBankKBN.ClientID).AppendLine("').style.cssText = StyleBankKBNYellow;")这一句是正确的。
    strbScript.AppendLine("if (document.getElementById('").Append(Me.rdbSiharaiOnly.ClientID).AppendLine("').checked == true){}")用相同的写法,想写在If判断句中就不管用了,请问错在哪里?
    该怎么改?
      

  9.   

    正解:strbScript.AppendLine("if(document.getElementById('"&Me.rdbSiharaiOnly.ClientID&"').checked == true){}")
      

  10.   

    你用jQuery阿,这个功能很好实现的