javascript - 如何一次进行两个验证并得到两个结果

标签 javascript html jquery-ui jquery

我创建了一个带有两个复选框的验证。

两种验证都可以使用 javascript 正常工作

让我给你看我的代码

javascript

function Validation_agree(){
    if(document.form1.agreed1.checked==false)
    {
        $(".agreement_main").show();
        return false
    }else{
        $(".agreement_main").hide();
    }

    if(document.form1.agreed2.checked==false)
    {
        $(".agreement_terms").show();
        return false
    }else{
        $(".agreement_terms").hide();
    }
}

形式就像

 <div class="checkme">
  <label><input type="checkbox" value="" name="agreed1" />I have discussed all of the order details above and the customer is happy to proceed</label>
<br />
  <div class="alert agreement_main" style="display:none;">Please confirm you have informed the customer of the T&amp;Cs</div>
</div>

 <div class="redNote">
 <label><input type="checkbox" value="" name="agreed2" />I have informed the customer where they can find the T&C’s on the BT.com website</label></p>
 <div class="alert agreement_terms" style="display:none;">Please confirm you have informed the customer of the T&amp;Cs</div>
 </div>


 <input type="submit" value="submit order" /></div>
</form>                    

问题是。一个在打败另一个后开始工作
当按下提交按钮时显示第一个验证错误消息。我想同时进行两项验证检查

谁能帮帮我 提前致谢

最佳答案

以下代码可能适合您。

function Validation_agree(){       
 var isValid = true;
 if(document.form1.agreed1.checked==false)       
  {           
      $(".agreement_main").show();           
         isValid = false;
   }else
    {           
      $(".agreement_main").hide();       
    }          
   if(document.form1.agreed2.checked==false)       
    {           
      $(".agreement_terms").show();           
       isValid = false;      
     }else{           
       $(".agreement_terms").hide();       
      }   
      return isValid;
}   

关于javascript - 如何一次进行两个验证并得到两个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8537569/

相关文章:

jQuery UI Datepicker - 日期值未正确传递

如果 jquery datepicker 已经在页面上,则 ajax 调用后它不起作用

javascript - Twitter Bootstrap 下拉菜单 - onclick 将 'open' 类放在祖先 ul 而不是子 ul 上

javascript - 使用 PHP 变量的值在 Javascript 中打开一个窗口

html - 尽管有 css 样式表,但细字体看起来很粗

python - 从python代码获取html输出

jQuery.sortable。通过 JavaScript 更改顺序

javascript - 为什么 HTML5 canvas 只在 webkit 浏览器中留下痕迹?

javascript - 'site url' : Uncaught TypeError: Cannot read property 'getColomnSet' of undefined with Selenium and Python 发生错误

javascript - 单击一个按钮对 jQuery 中的表格进行排序