標籤:
<!DOCTYPE HTML><html ng-app="myApp"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><style>.active1{ background:red;}.active2{ background:blue;}</style><script src="angular.min.js"></script><script>var m1 = angular.module(‘myApp‘,[]);m1.controller(‘Aaa‘,[‘$scope‘,function($scope){ $scope.dataList = [ ‘aaaaa‘ , ‘bbbbb‘ , ‘cccccc‘ , ‘dddddd‘ , ‘eeeeee‘ ];}]);</script></head><body><div ng-controller="Aaa"> <input type="checkbox" ng-model="aaa"> //checkbox選中則aaa為true <select> <option>11111</option> <option ng-selected="aaa">22222</option> //下拉選擇框是否選擇取決於aaa變數 </select> //輸入框變化就會出發輸入框的值為hello <input type="text" ng-change="bbb=‘hello‘" ng-model="bbb">{{bbb}}<br> //ng-paste="ccc=true"當輸入框複製操作時時ccc=true, <input type="text" value="aasdassssssss" ng-paste="ccc=true">{{ccc}}</div></body></html>
<!DOCTYPE HTML><html ng-app="myApp"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><script src="angular.min.js"></script><script>var m1 = angular.module(‘myApp‘,[]);m1.controller(‘Aaa‘,[‘$scope‘,‘$interval‘,function($scope,$interval){ var iNow = 5; $scope.text = iNow+‘秒‘; $scope.isDisabled = true; //setInterval -> $scope.$apply() //$timeout $interval var timer = $interval(function(){ iNow--; $scope.text = iNow+‘秒‘; if(iNow == 0){ $interval.cancel(timer); $scope.text = ‘可以點擊啦‘; $scope.isDisabled = false; } },1000);}]);</script></head><body><div ng-controller="Aaa"> //ng-disabled="isDisabled",isDisabled是變數名 <input type="button" ng-value="text" ng-disabled="isDisabled"> <input type="text" value="{{text}}" ng-readonly="isDisabled"> <input type="checkbox" value="{{text}}" ng-checked="isDisabled"></div><script>alert(1);</script></body></html>
<!DOCTYPE HTML><html ng-app="myApp"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><script src="angular.min.js"></script>//引入外掛程式,ngSanitize模組<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular-sanitize.min.js"></script><script>var m1 = angular.module(‘myApp‘,[‘ngSanitize‘]); //[‘ngSanitize‘]是引入ngSanitize模組m1.controller(‘Aaa‘,[‘$scope‘,function($scope){ $scope.text = ‘<h1>hello</h1>‘;}]);</script></head><body><div ng-controller="Aaa"> <div ng-bind="text"></div> //跟ng-value和寫運算式是一樣的 <div ng-bind-template="{{text}},{{text}}"></div> //ng-bind-template用於寫多個運算式 <div ng-bind-html="text"></div> //解析html內容,要引入ngSanitize模組 <div ng-cloak>{{text}}</div> //ng-cloak用於沒有解析完畢時不顯示解析完畢後解析,使用者體驗好。 <div ng-non-bindable>{{text}}</div> //原樣輸出,不進行解析。</div><script>alert(1); //阻止後面的js的執行</script></body></html>
<!DOCTYPE HTML><html ng-app="myApp"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><style>.red{ background:red;}.yellow{ background:yellow;}</style><script src="angular.min.js"></script><script>var m1 = angular.module(‘myApp‘,[]);m1.controller(‘Aaa‘,[‘$scope‘,function($scope){ $scope.text = ‘hello‘; $scope.style = "{color:‘red‘,background:‘yellow‘}"; $scope.sClass = "{red:true,yellow:true}"; $scope.url = "http://www.baidu.com";}]);</script></head><body><div ng-controller="Aaa"> <div ng-class="{red:true}">{{text}}</div> //啟用red樣式 <div ng-class="{red:true,yellow:true}">{{text}}</div> //啟用red和yellow樣式 <div ng-class="{{sClass}}">{{text}}</div> <div ng-style="{color:‘red‘,background:‘yellow‘}">{{text}}</div> <div ng-style="{{style}}">{{text}}</div> <a ng-href="{{url}}">aaaaaaa</a> <a ng-attr-href="{{url}}" ng-attr-title="{{text}}" ng-attr-class="" ng-attr-style="">aaaaaaa</a></div><script>alert(1); //阻止後面js的執行</script></body></html>
angularjs 標籤指令