AngularJS入門2-一個完整的例子

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   ar   java   sp   div   

 1 <!-- angular JS 完整的例子 --> 2 <DOCTYPE html> 3 <html> 4 <head> 5 <meta charset="utf-8"/> 6 <title>一個完整例子實驗</title> 7 <script src="jquery-1.10.2.min.js"></script> 8 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> 9 </head>10 <body>11 <div ng-controller="BoxCtrl">12      <div style="width:100px;height:100px;background-color:red;" ng-click="click()"></div>13      <p>{{w}}*{{h}}</p>14      <p>w:<input type="text" ng-model="w"></p>15      <p>h:<input type="text" ng-model="h"></p>16 </div>17 18 <script type="text/javascript" chartset="utf-8">19 var BoxCtrl=function($scope,$element){20     //$element是一個jquery對象21     var e=$element.children().eq(0);22     $scope.w=e.width();23     $scope.h=e.height();24     $scope.click=function(){25        $scope.w=parseInt($scope.w)+10;26        $scope.h=parseInt($scope.h)+10;27     }28     $scope.$watch(‘w‘,function(to,from) {29         e.width(to);30         }    31     );32     $scope.$watch(‘h‘,function(to,from){33          e.height(to);  34      });35 }36    angular.bootstrap(document.documentElement);37 </script>38 39 </body>40 </html>

 實現效果:實現在下方輸入框中輸入寬和高的值,上方div大小隨時動態更新

參考來源:http://www.zouyesheng.com/angular.html#toc3 感謝作者的分享

AngularJS入門2-一個完整的例子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.