angular.js - angularjs中怎么验证多选框至少选择一个?
给我你的怀抱
给我你的怀抱 2017-05-15 16:51:25
0
2
569

angularjs里面提供基础的表单验证,比如ng-minlength之类的属性,然后用form.inputname.$valid就可以进行判断是否验证通过

但是像checkbox这种多选框怎么验证啊?要验证至少选中一个,有没有内置的,感觉这种应该不用写很复杂吧?

给我你的怀抱
给我你的怀抱

reply all(2)
漂亮男人

I came up with the method myself, see the blog: angularjs form verification checkbox

刘奇
html<input type="checkbox" ng-model="form.cb1" ng-required="form.cb1 || form.cb2 || form.cb3">
<input type="checkbox" ng-model="form.cb2" ng-required="form.cb1 || form.cb2 || form.cb3">
<input type="checkbox" ng-model="form.cb3" ng-required="form.cb1 || form.cb2 || form.cb3">
If the judgment expression of

ngRequired is too long, just bind a function to return boolean.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!