angularjs怎么实现checkbox选中触发事件

angularjs怎么实现checkbox选中触发事件


ABOUTYOU
浏览 1618回答 3
3回答

大话西游666

$scope.sub()的参数去掉,然后在方法体里面加一句让$scope.showType取反HTML123456789101112131415<input&nbsp;type="checkbox"&nbsp;ng-click="sub()">选择&nbsp;&nbsp;&nbsp;<div&nbsp;ng-show="showType==1"&nbsp;class="btn">&nbsp;&nbsp;<button&nbsp;type="submit">提交申请</button></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div&nbsp;ng-show="showType!=1"&nbsp;class="btn">&nbsp;&nbsp;<button&nbsp;type="submit">提交申请</button></div>JS1234567var&nbsp;app&nbsp;=&nbsp;angular.module('test',&nbsp;[]);app.controller('chkCtrl',&nbsp;function($scope){&nbsp;&nbsp;&nbsp;&nbsp;$scope.showType=1;&nbsp;&nbsp;&nbsp;&nbsp;$scope.sub&nbsp;=&nbsp;function(){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$scope.showType=!$scope.showType;&nbsp;&nbsp;&nbsp;&nbsp;}};&nbsp;

小怪兽爱吃肉

html代码:<input type="checkbox" ng-click="sub(1)">选择<div ng-show="showType==1" class="btn"><button type="submit">提交申请</button></div><div ng-show="showType==2" class="btn"><button type="submit">提交申请</button></div>js代码:var app = angular.module('test', []);app.controller('chkCtrl', function($scope){$scope.showType=1;$scope.sub = function(type){if(type==1){$scope.showType =2;}else if( $scope.showType ==2){$scope.showType =1;}};这代码点击勾选的时候有效

杨__羊羊

<!DOCTYPE&nbsp;html><html ng-app="test"><head><title>angularJs-checkbox</title></head><body><div ng-controller="CheckCtrl"><input type="checkbox" ng-model="chk" ng-click="check(chk)"/></div><script type="text/javascript" src="../js/angular.min.js"></script><script type="text/javascript">//直接判断checkbox的model即可var test = angular.module('test', []);test.controller('CheckCtrl', function($scope){//设置checkbox默认不选中$scope.chk = false;$scope.check = function(val){!val ? alert('选中') : alert('未选中');}})</script></body></html>&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

AngularJS