<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="anglular/angular.js" ></script>
<script>
var app=angular.module("myApp",[]);
app.controller("myCtrl",function($scope){
$scope.phone=[
{id:80,name:"iphone",price:5400},
{id:290,name:"ipad",price:1420},
{id:500,name:"ipad air",price:2340},
{id:910,name:"imac",price:15400},
{id:1200,name:"ipad mini",price:2200}
];
$scope.flag="";
$scope.line="id";
$scope.product=function(line){
$scope.line=line;
if($scope.flag==""){
$scope.flag="-";
}else{
$scope.flag="";
}
}
$scope.xz="请选择";
$scope.ifShow=function(price){
if($scope.xz=="请选择"){
return true;
}else{
var arr=$scope.xz.split("-");
var xiao=arr[0];
var da=arr[1];
if(price<xiao||price>da){
return false;
}else{
return true;
}
}
}
$scope.erxz;
$scope.xzer=function(){
if($scope.erxz=="id"){
$scope.flag="";
$scope.line="id";
}else
if($scope.erxz=="-id"){
$scope.flag="-";
$scope.line="id";
}else
if($scope.erxz=="price"){
$scope.flag="";
$scope.line="price";
}else
if($scope.erxz=="-price"){
$scope.flag="-";
$scope.line="price";
}
}
$scope.dxsc=function(delname){
for(index in $scope.phone){
if(delname==$scope.phone[index].name){
$scope.phone.splice(index,1);
}else{
}
}
}
$scope.xg=function(price){
for(index in $scope.phone){
if(price==$scope.phone[index].price){
var result=parseInt(window.prompt("请输入要修改的金额",price));
if(result<0){
alert("输入有误,请重新修改");
}else{
if(window.confirm("确定要将"+$scope.phone[index].name+"的价格更改为"+result+"么?")){
$scope.phone[index].price=result;
};
}
}else{
}
}
}
$scope.quanxuan=false;
$scope.allfun=function(){
if($scope.quanxuan){
for(index in $scope.phone){
$scope.phone[index].state=true;
}
}else{
for(index in $scope.phone){
$scope.phone[index].state=false;
}
}
}
$scope.xuanze=function(){
var flag=false;
for(index in $scope.phone){
if(!$scope.phone[index].state){
flag=true;
}
}
if(flag){
$scope.quanxuan=false;
}else{
$scope.quanxuan=true;
}
}
$scope.del=function(){
var is=[];
for(index in $scope.phone){
if($scope.phone[index].state){
is.push($scope.phone[index]);
}
}
for(index in is){
var name=is[index].name;
for(index2 in $scope.phone){
if(name==$scope.phone[index2].name){
$scope.phone.splice(index2,1);
}
}
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<input type="text" placeholder="产品名称" ng-model="search"/>产品价格
<select ng-model="xz">
<option>请选择</option>
<option>1000-2000</option>
<option>2000-3000</option>
<option>3000-4000</option>
<option>4000-5000</option>
<option>5000-6000</option>
<option>6000-无穷大</option>
</select>
<select ng-model="erxz" ng-change="xzer()">
<option value="">排序方式</option>
<option value="id">id正序</option>
<option value="-id">id逆序</option>
<option value="price">价格正序</option>
<option value="-price">价格逆序</option>
</select>
<button ng-click="del()">批量删除</button><br /><br />
<table border="1px solid #000" cellpadding="10" cellspacing="0">
<tr>
<td> <input type="checkbox" ng-model="quanxuan" ng-click="allfun()" ></td>
<td ng-click="product('id')">产品编号</td>
<td ng-click="product('name')">产品名称</td>
<td ng-click="product('price')">产品价格</td>
<td>操作</td>
</tr>
<tr ng-repeat="sz in phone | filter:{'name':search} | orderBy:(flag+line)" ng-if="ifShow(sz.price)">
<td><input type="checkbox"ng-model="sz.state" ng-click="xuanze()"></td>
<td>{{sz.id}}</td>
<td>{{sz.name}}</td>
<td>{{sz.price}}</td>
<td><button ng-click="dxsc(sz.name)"> 删除</button><button ng-click="xg(sz.price)">修改</button></td>
</tr>
</table>
</center>
</body>
</html>
购物车修改排序删除
最新推荐文章于 2020-03-06 16:26:43 发布