AngularJs购物车代码。
来源:互联网 发布:直播看电视的软件 编辑:程序博客网 时间:2024/05/16 05:07
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>购物车</title>
<script type="text/javascript" src="js/angular.js"></script>
</head>
<body ng-app="product" ng-controller="productController">
<center>
<h2>商品列表</h2>
<div class="container">
<!--导航栏-->
<nav>
<div >
<div id="bs-example-navbar-collapse-1">
<div>
<input type="text" ng-model="search" placeholder="产品名称">
产品价格:
<select>
<option>0-1000</option>
<option>1000-2000</option>
<option>2000-5000</option>
</select>
<input type="button" style="background:#FF0000" value="全部删除" ng-click="removeAll()">
</div>
</div>
</div>
</nav><br />
<table border="1 solid" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th ng-click="sortProduct('id')">
产品编号
<span></span>
</th>
<th ng-click="sortProduct('name')">
产品名称
<span></span>
</th>
<th ng-click="sortProduct( 'price')">
产品价格
<span></span>
</th>
<th>
操作
<span></span>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in productList | filter:{ 'name':search} | orderBy:(orderSign+orderColumn) ">
<td>
{{item.id}}
</td>
<td>
{{item.name}}
</td>
<td>
{{item.price | currency:'(RMB)'}}
</td>
<td>
<input type="button" style="background:#FF0000" value="删除" ng-click="delProduct(item.name)">
</td>
</tr>
</tbody>
</table>
</div>
<script>
angular.module('product',[])
.factory('productList',function(){
return [
{ id:910,name:"imac",price:15400 },
{ id:80,name:"iphone",price:5400 },
{ id:29,name:"ipad",price:14200 },
{ id:500,name:"ipad air",price:23400 },
{ id:1200,name:"ipad mini",price:22000},
{ id:100,name:"android",price:9990 }
]
})
.controller('productController',function($scope,productList){
/*$scope.search = "ipad";//定义一个变量
alert($scope.search);*/
$scope.productList=productList
$scope.orderColumn='name'; //排序字段
$scope.orderSign='-'; //为空时正序 为负号时倒序
$scope.sortProduct=function(sortColumn){ //点击列标题排序事件
$scope.orderColumn=sortColumn;//觉得按照那一列进行排序
if($scope.orderSign=="-"){
$scope.orderSign="";
}else{
$scope.orderSign='-';
}
};
//删除产品
$scope.delProduct = function(name){
//alert(name);
if(name!=""){
if(confirm("是否删除"+name+"商品") ){
var p;
for (index in $scope.productList) {
p = $scope.productList[index];
if(p.name == name){
$scope.productList.splice(index,1);
}
}
}
}
}
//清空购物车
$scope.removeAll = function(){
if(confirm("你确定要清空购物车所有商品吗?")){
$scope.productList = [];
}
}
});
</script>
</center>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>购物车</title>
<script type="text/javascript" src="js/angular.js"></script>
</head>
<body ng-app="product" ng-controller="productController">
<center>
<h2>商品列表</h2>
<div class="container">
<!--导航栏-->
<nav>
<div >
<div id="bs-example-navbar-collapse-1">
<div>
<input type="text" ng-model="search" placeholder="产品名称">
产品价格:
<select>
<option>0-1000</option>
<option>1000-2000</option>
<option>2000-5000</option>
</select>
<input type="button" style="background:#FF0000" value="全部删除" ng-click="removeAll()">
</div>
</div>
</div>
</nav><br />
<table border="1 solid" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th ng-click="sortProduct('id')">
产品编号
<span></span>
</th>
<th ng-click="sortProduct('name')">
产品名称
<span></span>
</th>
<th ng-click="sortProduct( 'price')">
产品价格
<span></span>
</th>
<th>
操作
<span></span>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in productList | filter:{ 'name':search} | orderBy:(orderSign+orderColumn) ">
<td>
{{item.id}}
</td>
<td>
{{item.name}}
</td>
<td>
{{item.price | currency:'(RMB)'}}
</td>
<td>
<input type="button" style="background:#FF0000" value="删除" ng-click="delProduct(item.name)">
</td>
</tr>
</tbody>
</table>
</div>
<script>
angular.module('product',[])
.factory('productList',function(){
return [
{ id:910,name:"imac",price:15400 },
{ id:80,name:"iphone",price:5400 },
{ id:29,name:"ipad",price:14200 },
{ id:500,name:"ipad air",price:23400 },
{ id:1200,name:"ipad mini",price:22000},
{ id:100,name:"android",price:9990 }
]
})
.controller('productController',function($scope,productList){
/*$scope.search = "ipad";//定义一个变量
alert($scope.search);*/
$scope.productList=productList
$scope.orderColumn='name'; //排序字段
$scope.orderSign='-'; //为空时正序 为负号时倒序
$scope.sortProduct=function(sortColumn){ //点击列标题排序事件
$scope.orderColumn=sortColumn;//觉得按照那一列进行排序
if($scope.orderSign=="-"){
$scope.orderSign="";
}else{
$scope.orderSign='-';
}
};
//删除产品
$scope.delProduct = function(name){
//alert(name);
if(name!=""){
if(confirm("是否删除"+name+"商品") ){
var p;
for (index in $scope.productList) {
p = $scope.productList[index];
if(p.name == name){
$scope.productList.splice(index,1);
}
}
}
}
}
//清空购物车
$scope.removeAll = function(){
if(confirm("你确定要清空购物车所有商品吗?")){
$scope.productList = [];
}
}
});
</script>
</center>
</body>
</html>
阅读全文
0 0
- AngularJS购物车代码
- AngularJs购物车代码。
- ionis 和angularjs 购物车的代码
- angularjs的简易购物代码
- 【AngularJS】购物车实例
- AngularJS 购物车实例
- AngularJS-购物车Demo
- angularJS 购物车练习
- 购物车AngularJs
- angularJs购物车
- angularjs bootstrap 购物车
- angularjs完成购物车
- 购物车angularJS
- Angularjs 完成购物车
- AngularJs购物车实现
- angularJs 购物车
- angularjs购物车
- angularjs购物车
- struts文件上传
- 侧拉 DrawerLayout
- Hadoop学习笔记(三)漫画解读HDFS读写原理
- 用c语言求解一元二次方程
- 注册表单验证的模块
- AngularJs购物车代码。
- Codeforces Round #440 (A-C ) 题解
- Unix Shell编程——有序输出参数列表
- Android仿博雅斗地主
- 反射学习
- 工具、插件乱七八糟下载链接(用到时补充)
- PTA 6-1 爆内存函数实例
- NOIP 2013 货车运输
- HDU