扫码关注官方订阅号
Red Blue Green 提交
如何实现点击提交当checkbox选中超过2个做出提示即可
form和from写的好错乱
form
from
js var app= angular.module('fromApp',[]); app.controller('formController',function($scope){ $scope.fromData={}; $scope.check=function(){ if($scope.fromData.favoriteColors){ var log = []; angular.forEach($scope.fromData.favoriteColors,function(v){ if(v==true) this.push(v); },log); console.log(log.length);//length } } });
js
var app= angular.module('fromApp',[]); app.controller('formController',function($scope){ $scope.fromData={}; $scope.check=function(){ if($scope.fromData.favoriteColors){ var log = []; angular.forEach($scope.fromData.favoriteColors,function(v){ if(v==true) this.push(v); },log); console.log(log.length);//length } } });
为什么不用radio呢
如果真要这样,可以
$scope.check=function(){ var checked=[]; if(!$scope.formData.favoriteColors){ return false; } if($scope.formData.favoriteColors.red) checked.push('red'); if($scope.formData.favoriteColors.blue) checked.push('blue'); if($scope.formData.favoriteColors.green) checked.push('green');
if (checked.length>=2){ ... }
}`
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
form和from写的好错乱为什么不用radio呢
如果真要这样,可以
$scope.check=function(){
var checked=[];
if(!$scope.formData.favoriteColors){
return false;
}
if($scope.formData.favoriteColors.red)
checked.push('red');
if($scope.formData.favoriteColors.blue)
checked.push('blue');
if($scope.formData.favoriteColors.green)
checked.push('green');
}`