1 <!DOCTYPE html> 2 <html ng-app="consoleApp"> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title>mytest</title> 6 </head> 7 <body ng-controller="appCtrl" > 8 9 <input type="checkbox" ng-model="che" ng-change="change()"/> 10 11 <div ng-switch on="eip"> 12 <span ng-switch-when="checked">1</span> 13 <span ng-switch-when="add">2</span> 14 <span ng-switch-when="add1">3</span> 15 </div> 16 17 </body> 18 19 <script src="angular.js"></script> 20 <script> 21 var consoleApp=angular.module(‘consoleApp‘,[]); 22 consoleApp.controller(‘appCtrl‘,[‘$scope‘,function($scope){ 23 24 25 if($scope.che===undefined){ 26 $scope.eip = ‘add1‘; 27 }else if($scope.che === true){ 28 $scope.eip = ‘checked‘; 29 }else if($scope.che === false){ 30 $scope.eip=‘add‘ 31 } 32 33 $scope.change = function(){ 34 if($scope.che===‘undefind‘){ 35 $scope.eip = ‘add1‘; 36 }else if($scope.che === true){ 37 $scope.eip = ‘checked‘; 38 }else if($scope.che === false){ 39 $scope.eip=‘add‘ 40 } 41 } 42 }]) 43 </script> 44 </html>
时间: 2024-10-23 22:14:31