search

Home  >  Q&A  >  body text

angular.js - form 表单,点击提交按钮 判断ng-checked 已选中

点击提交按钮,若没有选中,则提示没有勾选
下面是代码

<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(" 请同意并勾选!");
}

如果没有勾选我已阅读并同意,点击注册后,应提示需要勾选。

求指点,谢谢。。。

给我你的怀抱给我你的怀抱2745 days ago672

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