• <small id='lipPk'></small><noframes id='lipPk'>

    1. <legend id='lipPk'><style id='lipPk'><dir id='lipPk'><q id='lipPk'></q></dir></style></legend>

      <tfoot id='lipPk'></tfoot>

    2. <i id='lipPk'><tr id='lipPk'><dt id='lipPk'><q id='lipPk'><span id='lipPk'><b id='lipPk'><form id='lipPk'><ins id='lipPk'></ins><ul id='lipPk'></ul><sub id='lipPk'></sub></form><legend id='lipPk'></legend><bdo id='lipPk'><pre id='lipPk'><center id='lipPk'></center></pre></bdo></b><th id='lipPk'></th></span></q></dt></tr></i><div id='lipPk'><tfoot id='lipPk'></tfoot><dl id='lipPk'><fieldset id='lipPk'></fieldset></dl></div>
      • <bdo id='lipPk'></bdo><ul id='lipPk'></ul>

        通过 JavaScript 验证单选按钮

        时间:2023-10-21
        <tfoot id='p9iHs'></tfoot>

            <legend id='p9iHs'><style id='p9iHs'><dir id='p9iHs'><q id='p9iHs'></q></dir></style></legend>

            <small id='p9iHs'></small><noframes id='p9iHs'>

            • <bdo id='p9iHs'></bdo><ul id='p9iHs'></ul>

                    <tbody id='p9iHs'></tbody>
                  <i id='p9iHs'><tr id='p9iHs'><dt id='p9iHs'><q id='p9iHs'><span id='p9iHs'><b id='p9iHs'><form id='p9iHs'><ins id='p9iHs'></ins><ul id='p9iHs'></ul><sub id='p9iHs'></sub></form><legend id='p9iHs'></legend><bdo id='p9iHs'><pre id='p9iHs'><center id='p9iHs'></center></pre></bdo></b><th id='p9iHs'></th></span></q></dt></tr></i><div id='p9iHs'><tfoot id='p9iHs'></tfoot><dl id='p9iHs'><fieldset id='p9iHs'></fieldset></dl></div>
                1. 本文介绍了通过 JavaScript 验证单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下表格:

                  <form name="survey1" action="add5up.php" method="post" onsubmit="return validateForm()">
                  <div id="question">Q1) My programme meets my expectations</div><br />
                  Always<INPUT  TYPE = 'Radio' Name ='q1'  value= 'a'> 
                  Usually<INPUT  TYPE = 'Radio' Name ='q1' value= 'b'> 
                  Rarely<INPUT  TYPE = 'Radio' Name ='q1' value= 'c'> 
                  Never<INPUT  TYPE = 'Radio' Name ='q1' value= 'd'> 
                  <input type="submit" value="addData" />
                  </form>
                  

                  我正在尝试验证是否选择了 Radio 按钮.

                  I am trying to validate whether a Radio button has been selected.

                  我正在使用的代码:

                  <script type="text/javascript">
                  function validateForm()
                  {
                  if( document.forms["survey1"]["q1"].checked)
                  {
                      return true;
                  }
                  
                  else
                  {
                      alert('Please answer all questions');
                      return false;
                  }
                  }
                  </script>
                  

                  这不起作用.有什么想法吗?

                  This is not working. Any ideas?

                  推荐答案

                  当使用单选按钮时,你必须检查它们是否被选中,因为 javascript 将它们作为数组威胁:

                  When using radiobuttons you have to go through to check if any of them is checked, because javascript threats them as an array:

                  <script type="text/javascript">
                  function validateRadio (radios)
                  {
                      for (i = 0; i < radios.length; ++ i)
                      {
                          if (radios [i].checked) return true;
                      }
                      return false;
                  }
                  
                  function validateForm()
                  {
                      if(validateRadio (document.forms["survey1"]["q1"]))
                      {
                          return true;
                      }
                      else
                      {
                          alert('Please answer all questions');
                          return false;
                      }
                  }
                  </script>
                  

                  问候

                  这篇关于通过 JavaScript 验证单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何更改单选按钮的值 下一篇:没有标签的样式单选按钮

                  相关文章

                2. <tfoot id='gLhOf'></tfoot>
                3. <i id='gLhOf'><tr id='gLhOf'><dt id='gLhOf'><q id='gLhOf'><span id='gLhOf'><b id='gLhOf'><form id='gLhOf'><ins id='gLhOf'></ins><ul id='gLhOf'></ul><sub id='gLhOf'></sub></form><legend id='gLhOf'></legend><bdo id='gLhOf'><pre id='gLhOf'><center id='gLhOf'></center></pre></bdo></b><th id='gLhOf'></th></span></q></dt></tr></i><div id='gLhOf'><tfoot id='gLhOf'></tfoot><dl id='gLhOf'><fieldset id='gLhOf'></fieldset></dl></div>

                    <legend id='gLhOf'><style id='gLhOf'><dir id='gLhOf'><q id='gLhOf'></q></dir></style></legend>
                      <bdo id='gLhOf'></bdo><ul id='gLhOf'></ul>

                    1. <small id='gLhOf'></small><noframes id='gLhOf'>