美文网首页
JS-购物车

JS-购物车

作者: Meimaobing | 来源:发表于2017-09-18 20:43 被阅读0次


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>周考三</title>
    <script src="angular1.4.6.min.js"></script>
    <script>
        var app = angular.module("myApp", []);
        app.controller("myctrl", function ($scope) {
            $scope.goods = [
                {"id": 124, "name": "iphone", "price":"¥:5400", "num": 55,},
                {"id": 154, "name": "ipad", "price": "¥:2300", "num": 25,},
                {"id": 125, "name": "ionic", "price": "¥:9400", "num": 85,},
                {"id": 185, "name": "Andriod", "price":" ¥:3800", "num": 10,},
            ];
            $scope.bold = "bold";
            $scope.title = 'name';
            $scope.desc = 0;
            $scope.key = '';

            //删除
            $scope.deletes =function(name){

                var p;
                for( index in     $scope.goods){
                    p = $scope.goods[index];
                    if( p.name == name){
                        $scope.goods.splice(index,1);
                        alert("是否删除"+name+"商品");
                    }

                }

            };
            $scope.delall =function(){
                alert("删除全部");
                $scope.goods.splice($scope.goods);
            };

            //根据标题title排序
            $scope.togg =function(tit){
                $scope.title = tit;
                $scope.desc = !$scope.desc;

            };

        });

    </script>

</head>
<body ng-app="myApp" ng-controller="myctrl">
<center>
    <table cellpadding="10" cellspacing="0" border="1">
        <tr>

            <th><input type="text" ng-model="key" placeholder="请输入关键字"></th>
            <th colspan="5" align="right" ng-click="delall()"><button style="background-color: red">批量删除</button></th>
        </tr>
        <tr>
            <th><input type="checkbox"> </th>
            <th ng-click="goods("id=")">商品编号</th>
            <th ng-click="goods("name=")">商品名称</th>
            <th ng-click="goods("price=")">商品价格</th>
            <th ng-click="goods("num=")">商品库存</th>
            <th>数据操作</th>
        </tr>
        <tr ng-repeat="x in goods | filter: {name: key} | orderBy: title : desc">
            <th><input type="checkbox"> </th>
            <td>{{x.id}}</td>
            <td>{{x.name}}</td>
            <td>{{x.price}}</td>
            <td>{{x.num}}</td>
            <td>
                <button ng-click="deletes(x.name)") style="background-color: goldenrod">删除</button>
            </td>
        </tr>

    </table>
</center>
</body>
</html>








相关文章

网友评论

      本文标题:JS-购物车

      本文链接:https://www.haomeiwen.com/subject/yyxisxtx.html