3 回答
TA贡献1817条经验 获得超14个赞
$scope.sub()的参数去掉,然后在方法体里面加一句让$scope.showType取反
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <input type="checkbox" ng-click="sub()">选择
<div ng-show="showType==1" class="btn"> <button type="submit">提交申请</button> </div>
<div ng-show="showType!=1" class="btn"> <button type="submit">提交申请</button> </div> |
JS
1 2 3 4 5 6 7 | var app = angular.module('test', []); app.controller('chkCtrl', function($scope){ $scope.showType=1; $scope.sub = function(){ $scope.showType=!$scope.showType; } }; |
TA贡献1852条经验 获得超1个赞
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;
}
};
这代码点击勾选的时候有效
TA贡献1943条经验 获得超7个赞
<!DOCTYPE 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>
- 3 回答
- 0 关注
- 1606 浏览
添加回答
举报