Jquery 使用BootstrapValidator验证单选按钮

Jquery 使用BootstrapValidator验证单选按钮,jquery,bootstrapvalidator,Jquery,Bootstrapvalidator,我有一点不同的情况。我有两个单选按钮,是和否。 第一次验证需要确保至少检查其中一个。这部分很好用。 第二部分需要确保选中了No,因为No是唯一有效的选项。如果他们选择“是”,则应继续提示他们 通常我会对此使用复选框,但企业希望强制选择是或否。 我想也许我可以增加一些选择,但这并不能满足我的需要 optionPlan: { validators: { notEmpty: { message: 'Pleas

我有一点不同的情况。我有两个单选按钮,是和否。 第一次验证需要确保至少检查其中一个。这部分很好用。 第二部分需要确保选中了No,因为No是唯一有效的选项。如果他们选择“是”,则应继续提示他们

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

optionPlan: {
               validators: {
                notEmpty: {
                message: 'Please select Yes or No'
                },
             }
}
或者您可以使用:

<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>

请登录


对 不
登录 如果($('input[name=yes]:选中')。长度>0){ //在这里做点什么 警告(“您需要选择否!”); }
或者您可以使用:

<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>

请登录


对 不
登录 如果($('input[name=yes]:选中')。长度>0){ //在这里做点什么 警告(“您需要选择否!”); }