【问题标题】:Validating radio buttons with BootstrapValidator使用 BootstrapValidator 验证单选按钮
【发布时间】:2016-10-29 19:28:07
【问题描述】:

我有一点不同的情况。我有 2 个单选按钮,是和否。 第一次验证需要确保至少检查其中一个。这部分工作正常。 第二部分需要确保选中否,因为否是唯一有效的选项。如果他们选择是,它应该继续提示他们。

通常我会为此使用复选框,但企业希望强制选择是或否。 我想也许我可以增加一些选择,但这并不能满足我的需要。

optionPlan: {
               validators: {
                notEmpty: {
                message: 'Please select Yes or No'
                },
             }
}

【问题讨论】:

    标签: jquery bootstrapvalidator


    【解决方案1】:
    if ($('input[name=yes]:checked').length > 0) {
        // do something here
       alert("you need to select no !");
    }
    

    【讨论】:

      【解决方案2】:

      或者你可以使用:

      <form class="form-signin" action="firstLogin.action" method="post">
           <h2 class="form-signin-heading">Please sign in</h2>
      
          <input type="text" class="form-control" name="username" placeholder="User Name">
          <br>
          <input type="password" class="form-control" name="password"placeholder="Password">
          <br>
          <div >
              <input type="radio" name="yes">Yes</input>
              <input type="radio" name="radio-choice" required>No</input> 
          </div>
          <div>
          <br>
          <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
      </form>
      <script>
      if ($('input[name=yes]:checked').length > 0) {
          // do something here
         alert("you need to select no !");
      
      }
      </script>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-07
        • 1970-01-01
        • 2013-01-24
        • 2012-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多