search

Home  >  Q&A  >  body text

angular.js - form form, click the submit button to determine whether ng-checked has been selected

Click the submit button. If it is not selected, it will prompt that it is not checked
The following is the code

<p class="form-group check_protocol">
    <p class="col-sm-12 text-center">
        <input type="checkbox" ng-checked="choose"
                name="checkbox"
                required="required"
                >
        我已阅读并同意
        <a href="javascript:;" id="protocol"  data-toggle="modal" data-target="#myModal">《用户注册协议》</a>
        <span ng-messages="checkForm.checkbox.$error.choose" role="alert">
            <span class="error_text" ng-message="choose" style="color: #ff0000;">请勾选协议!</span>
        </span>
    </p>
</p>
if($scope.checkForm.checkbox){
    alert(" 请同意并勾选!");
}

If I have read and agree is not checked, after clicking register, you should be prompted to check it.

Please give me some advice, thank you. . .

给我你的怀抱给我你的怀抱2815 days ago697

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-15 17:06:01

    <input type="checkbox" ng-model="checkTest" />
    <span ng-show="!checkbox" role="alert">
            <span class="error_text" style="color: #ff0000;">请勾选协议!</span>
    </span>
    

    Just check whether $scope.checkTest is true in the controller. If not, it will prompt you. If it is, submit it. Written like this, no other judgment is needed! You can hide the prompt information first when the controller is initialized.
    Kids, frameworks are just to make development easier for us. There is no need to use frameworks for everything. Writing code should be simple, easy to understand and readable!

    reply
    0
  • Cancelreply