使用BootstrapValidator

时间:2016-10-29 19:28:08

标签: jquery bootstrapvalidator

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

通常情况下,我会使用一个复选框,但企业要强制使用是或否。 我想也许我可以添加选择,但那并不能满足我的需要。

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

或者您可以使用:

<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>
相关问题