AngularJS使用ng-style动态改变样式,代码如下:
04 | <meta charset= "UTF-8" /> |
05 | <title>Document</title> |
06 | <style type = "text/css" > |
07 | .ng-cloak{display:none;} |
10 | <body ng-app= "app" ng-controller= "ctrl" ng-cloak class= "ng-cloak" > |
11 | <input type = "text" ng-model= "color" /> |
12 | <input type = "number" ng-model= "num" /> |
13 | <p ng-style= "{'color':color, 'fontSize':num+'px'}" >赵一鸣技术博客</p> |
17 | <script type = "text/javascript" > |
18 | var m = angular.module( 'app' , []); |
19 | m.controller( 'ctrl' , [ '$scope' , function ($scope){ |
|
注意:ng-style里边是json格式,与jquery定制css样式类似,比如字体大小应该是fontSize,而不是font-size.