码迷,mamicode.com
首页 > 其他好文 > 详细

angular笔记_2

时间:2017-12-20 03:48:02      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:click   angular   doc   utf-8   ice   button   gpo   提交   html   

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div ng-app="hd" ng-controller="ctrl">
名称:<input type="text" ng-model="good.title" readonly="readonly" /><br/>
单价:<input type="text" ng-model="good.price" readonly="readonly" /><br/>
数量:<input type="text" ng-model="good.num" /><br/>
总价:<input type="text" ng-value="good.num * good.price"/>
<br/><br/><br/>
商品名称:{{goods.data.title}}<br/>
商品价格:{{goods.data.price}}<br/>
商品数量:{{goods.data.num}}<br/>
商品总价:{{goods.data.num * goods.data.price}}<br/>
<button ng-click="goods.add()" >增加</button>
<button ng-click="goods.reduce()" >减少</button>
<br/><br/><br/>
<form action="1.php" method="post">
<input type="text" ng-model="name" name="name" />
<input type="submit" value="提交"/>
</form>
</div>
<script>
var m=angular.module(‘hd‘,[]);
m.controller(‘ctrl‘,[‘$scope‘,function($scope){
$scope.name="数据提交";
$scope.good={‘title‘:‘oppo‘,‘price‘:300,num:2};
$scope.add=function(){
$scope.good.num=Math.min(++$scope.good.num,6);
//$scope.goods.num=6?6:++$scope.goods.num

}
$scope.reduce=function(){
$scope.good.num=Math.max(--$scope.good.num,0); //
}

//整理成对象
$scope.goods={
data:{‘title‘:‘apple‘,‘price‘:3000,num:0},
add:function(){
$scope.goods.data.num=Math.min(++$scope.goods.data.num,6);
},
reduce:function(){
$scope.goods.data.num=Math.max(--$scope.goods.data.num,0); //
}
};

}]);
</script>

</body>
</html>

angular笔记_2

标签:click   angular   doc   utf-8   ice   button   gpo   提交   html   

原文地址:http://www.cnblogs.com/yewook/p/8067635.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!