<!doctype html>
<html ng-app>
<head>
<script src ="Scripts/angular.min.js"></script>
<script>
function InvoiceCntl($scope) {
$scope.qty = 1;
$scope.cost = 19.95;
}
</script>
</head>
<body>
<div ng-controller="InvoiceCntl">
<b>Invoice:</b>
<br>
<br>
<table>
<tr><td>Quantity</td><td>Cost</td></tr>
<tr>
<td><input type="integer" min="0" ng-model="qty" required ></td>
<td><input type="number" ng-model="cost" required ></td>
</tr>
</table>
<hr>
<b>Total:</b> {{qty * cost | currency}}
</div>
</body>
</html>
<!DOCTYPE html>
<html ng-app>
<head>
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.7.2.js"></script>
<script type="text/javascript" src="Scripts/angular.min.js"></script>
<script type="text/javascript">
function onTestClick(){ //jquery和angular交互
var tx= $('#test').scope().testvalue;
alert(tx);
$('#test').scope().testvalue = '12345';
$('#test').scope().$digest();
}
var TestCtrl = function($scope){ //angular方式,實現雙向綁定
$scope.testvalue = '123';
}
angular.bootstrap(document, document.documentElement);
</script>
</head>
<body>
<div id="test" ng-controller="TestCtrl">
<p>{{ testvalue }} </p>
<input type="text" value="" id="a" ng-model="testvalue"/>
<button οnclick="onTestClick()">ClickMe</button>
</div>
</body>
</html>
關於angularjs,業餘時間有興趣的可以先了解一下,接觸下網頁的新思路,除了http://www.angularjs.cn外(沒有上一頁下一頁,不爽),推薦幾個網址:
入門:http://www.ituring.com.cn/article/13472
配套示例代碼可以從這裏獲取:http://www.worlduc.com/blog2012.aspx?bid=17596841
進階可以看《angularjs開發指南》,但基本是官方翻譯文檔,不少東西不好理解,推薦一個網址,作者學習的經驗總結,容易體會,也適合從入門就開始看:
http://zouyesheng.com/angular.html#toc1