自学 js

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			tr:nth-child(odd){
				background: gainsboro;
			}
			tr:nth-child(even){
				background: grey;
			}
			#aaa{
				margin-left: 420px;
				background: orange;
			}
			#gm{
				background: green;
			}
			#pre{
				margin-right: 200px;
				margin-top: 20px;
			}
			#next{
				margin-left: 200px;
				margin-top: 20px;
			}
			table{
				margin-top: 20px;
			}
		</style>
		<script src="../js/jquery-1.8.2.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/angular.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			angular.module("myapp",[]).controller("myctrl",function($scope,$http){
				/*网络接口*/
				$http.get("http://result.eolinker.com/rR1VBtT56a6bb220c10b3d44b65b4787a8aec03c4ec32ce?uri=monthTest").then(function(success){
					$scope.shop=success.data;
				})
				/*批量删除*/
				$scope.alldel=function(){
					if($scope.shop.checked==false||$scope.shop.length==0){
						alert("请选择至少一条数据");
					}
					else if (confirm("你确定删除它们?")) {
						for (var i = 0; i < $scope.shop.length; i++) {
							if ($scope.shop[i].checked==true) {
								$scope.shop.splice(i,1);
								i--;
							}
						}
					}
				}
				/*全选*/
				$scope.allck=function(){
					var cks=$scope.ischeck;
					for (var i = 0; i < $scope.shop.length; i++) {
						$scope.shop[i].checked=cks;
					}
				}
				/*购买*/
				$scope.buy=function(index){
					var num=$scope.shop[index].number;
					if (num>0) {
						alert("购买成功");
						$scope.shop[index].number--;
						$scope.shop[index].sells++;
					}else{
						alert("库存不足");
					}
				}
			})
		</script>
	</head>
	<body ng-app="myapp" ng-controller="myctrl">
		<input type="text"  ng-model="sele" placeholder="输入关键字..."/>
		<button ng-click="selec=sele">搜索</button>
		<button ng-click="alldel()" id="aaa">批量删除</button>
		<br />
		<table border="1px" width="700px">
			<tr style="background: gray;">
				<td><input type="checkbox" ng-model="ischeck" ng-change="allck()"/></td>
				<td>商品名称</td>
				<td>
					商品价格
					<button ng-click="pxa='price';ss=!ss">排序</button>
				</td>
				<td>
					库存
					<button ng-click="pxb='number';sj=!sj">排序</button>
				</td>
				<td>
					月销量
					<button ng-click="pxc='sells';aa=!aa">排序</button>
				</td>
				<td>购买</td>
			</tr>
			<tr ng-repeat="s in shop|filter:selec|orderBy:pxa:ss|orderBy:pxb:sj|orderBy:pxc:aa">
				<td><input type="checkbox" ng-model="s.checked"/></td>
				<td>{{s.name}}</td>
				<td>{{s.price|currency:"¥"}}</td>
				<td>{{s.number}}</td>
				<td>{{s.sells}}</td>
				<td>
					<button ng-click="buy($index)" id="gm">购买</button>
				</td>
			</tr>
		</table>
		<button id="pre">上一页</button>
		<button id="next">下一页</button>
	</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值