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

解决方案 »

  1.   


    JS里的代码
    <script language="javascript">
    function check()
    {
    if(document.fr.sex[0].checked==false&&document.fr.sex[1].checked==false)
    {
    alert("性别必须选择其一!");
    return false;
    }
    }
    页面
    <form action="<%=request.getContextPath() %>/EmpServlet?action=add" name="fr" method="post" onsubmit="return check()">
    <input type="radio" name="sex" value="男" >男<input type="radio" name="sex" value="女" >女
    </from>
      

  2.   

    就是检查 checked 属性,自己查手册吧
    Web 开发常用手册DHTML 参考手册
    http://download.csdn.net/source/308913JScript 语言参考
    http://download.csdn.net/source/308916CCS 样式表中文手册
    http://download.csdn.net/source/304124
      

  3.   


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

  4.   


    你这里边的fr  ,   sex[0]  具体是什么东西?
      

  5.   

    //判断第一个单选按钮的和第二个单选按钮的选择状态,如果都为false,代表都没选中。
    if(document.fr.sex[0].checked==false&amp;&amp;document.fr.sex[1].checked==false)
    fr 是form表单id,sex[0]第一个单选按钮。意思就是:id为fr,下面的第一个单选按钮
      

  6.   

    没错,就是通过checked这个属性来判断的。如查是true就是被选中的,是false就是没被选中的。
      

  7.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
    <head>
    <title>Untitled</title>
     <script>
        function isChecked(obj){
            if(obj.checked==true){
                alert("你选种的是" + obj.value);
            }
        }
     </script>
    </head><body><form>
    <input type="radio" name="love" onclick="isChecked(this)" value="a">a
    <input type="radio" name="love" onclick="isChecked(this)" value="b">b
    </form></body>
    </html>
      

  8.   


    if (document.getElementById('").Append(Me.rdbSiharaiOnly.ClientID).AppendLine("').checked == true)这样写为什么不行呢?
      

  9.   

    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判断句中就不管用了,请问错在哪里?
    该怎么改?
      

  10.   

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