Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用AngularJS验证单选按钮集_Javascript_Angularjs_Angular Validation - Fatal编程技术网

Javascript 使用AngularJS验证单选按钮集

Javascript 使用AngularJS验证单选按钮集,javascript,angularjs,angular-validation,Javascript,Angularjs,Angular Validation,我的代码如下所示: <ng-form name="form"> <div> Question 1 <label> <input type="radio" ng-model="q1" style="visibility: initial; position: relative;" ng-value="false">

我的代码如下所示:

 <ng-form name="form">

    <div>
        Question 1
        <label>
            <input type="radio" ng-model="q1" style="visibility: initial; position: relative;"
                   ng-value="false">
               No
        </label>

        <label>
            <input type="radio" ng-model="q1" style="visibility: initial; position: relative;"
                   ng-value="true" ng-required="!(q1||q2||q3)">
                Yes
        </label>

    </div>

    <div  ng-show="!q1">
        Question 2 
        <br/>
        <label>
            <input type="radio" ng-model="q2" style="visibility: initial; position: relative;"
                   ng-value="false">
            No            </label>
        <br/>
        <label>
            <input type="radio" ng-model="q2" style="visibility: initial; position: relative;"
                   ng-value="true" ng-required="!(q1|| q2|| q3)">
                Yes            </label>
        <br/>
    </div>

    <div ng-show="!q1 && !q2">
       Question 3
        <br/>
        <label>
            <input type="radio" ng-model="q3" style="visibility: initial; position: relative;"
                   ng-value="false">
                No
        </label>
        <br/>
        <label>
            <input type="radio" ng-model="q3" style="visibility: initial; position: relative;"
                   ng-value="true" ng-required="!(q1|| q2|| q3)">
                Yes
        </label>
        <br/>

    </div>

    </ng-form>

问题1
不
是的
问题2


是的
问题3

是的
所以,我需要一个(而且只有一个)“是”的问题答案。但是,$form.invalid始终为false。我看到'required=“required”'在应该添加时已成功添加到输入字段,因此ng required condition工作正常;)


按组为无线电输入命名。否则表单将无法检查验证

谢谢。。。但我还是不知道我该怎么做。我添加了jsfiddle。有什么想法吗?:)