Javascript 组无线电输入验证

Javascript 组无线电输入验证,javascript,jquery,Javascript,Jquery,我对附加错误状态没有什么问题。我得到了7个无线电输入,提交后,我得到了组下的7个错误状态 有人能帮我弄清楚如何修改代码吗 <form class="register-form"> <div class="col-lg-8 col-lg-offset-2 col-md-8 col-md-offset-2 col-sm-10 col-sm-offset-1 margin-top-20"> <h4 c

我对附加错误状态没有什么问题。我得到了7个无线电输入,提交后,我得到了组下的7个错误状态

有人能帮我弄清楚如何修改代码吗

<form class="register-form">
                <div class="col-lg-8 col-lg-offset-2 col-md-8 col-md-offset-2 col-sm-10 col-sm-offset-1 margin-top-20">
                    <h4 class="text-center"> TEST TEST</h4>
                    <div class="question-box">
                        <p class="margin-top-20"><span class="red">*</span>1. QUESTION.</p>
                        <div class="col-lg-6 col-lg-offset-3 form-group text-center question">

                            <div class="radio-item" >
                                <input type="radio" id="case1" name="case" value="0-50" required data-step2="1">
                                <label for="case1">0 - 50</label>
                            </div>

                            <div class="radio-item">
                                <input type="radio" id="case2" name="case" value="50-100" required data-step2="1">
                                <label for="case2">50 - 100</label>
                            </div>
                            <div class="radio-item">
                                <input type="radio" id="case3" name="case" value="100+" required data-step2="1">
                                <label for="case3">Over 100</label>
                            </div>
                        </div>
                    </div>
                    <div class="question-box">
                        <p class="margin-top-20"><span class="red">*</span>2. QUESTION</p>

                        <div class="col-lg-6 col-lg-offset-3 form-group text-center question">

                            <div class="radio-item">
                                <input type="radio" id="resell1" name="resell" value="1" required data-step2="1">
                                <label for="resell1">YES</label>
                            </div>
                            <div class="radio-item">
                                <input type="radio" id="resell2" name="resell" value="0" required data-step2="1">
                                <label for="resell2">NO</label>
                            </div>
                        </div>
                    </div>
                    <div class="question-box">
                        <p class="margin-top-20"><span class="red">*</span>3.QUESTION</p>
                        <div class="col-lg-6 col-lg-offset-3 form-group text-center question">
                            <div class="radio-item">
                                <input type="radio" id="export1" name="export" value="1" required data-step2="1">
                                <label for="export1">YES</label>
                            </div>
                            <div class="radio-item">
                                <input type="radio" id="export2" name="export" value="0" required data-step2="1">
                                <label for="export2">NO</label>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 margin-top-20 text-center">
                    <button id="submit-registration" type="submit" class="btn btn-success radius send" >Continue</button>
                </div>
            </form>

测试

*1。问题

0 - 50 50 - 100 百余

*2。问题:

对 不

*3.问题

对 不 继续


thx

我在您的代码中更改了一些内容,我认为这可能就是您想要的

下面的第一个代码将在
输入的
属性中循环。这意味着它将只运行3次

 $(".invalid-info").remove(); // Removes the error messages before we run the validation.
 var group = {};
 $('input[name^="case"], input[name^="resell"], input[name^="export"]').each(function(index) {
   var $this = $(this);
   var name = this.name;
   if (!group[name]) {
     group[name] = true;
     if (!testRadio($this, options.showValidOnCheck)) validated = false;
   }
 });
我变了

var value = $form.find('input[name="' + name + '"]').is(":checked");


if (!value) {
   $('<p class="invalid-info" style="color: red">Please choose corect answer</p>').appendTo($($input).parent().parent())
   return false;

}
var value=$form.find('input[name=“”+name+“]”)。是(“:checked”);
如果(!值){
$('

请选择正确答案。$($input.parent().parent()) 返回false; }


让我知道这是否是您要查找的内容。

您正在使用“问题”类在每个元素中追加错误。appendTo(“.question”)不在与错误相关的父项下。好的,但我仍然得到了7次,而不是1次:(验证多个无线电的示例:@RobDee查看我的answer@CarstenL是的!我现在就想这么做。谢谢