AngularJs心得

<i><%@page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + path + "/";
    %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'Goods.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
<link rel="stylesheet"
    href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
<script
    src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/angularjs.js"></script>
<script type="text/javascript" src="js/jquery-2.1.0.js"></script>
<script type="text/javascript">
    var app = angular.module("myapp", []);
    //进来就查询所有商品
    app.controller("myController", function($scope, $http) {
        $http.post("GoodsController/findGoods").success(function(obj) {

            $scope.product = obj;
        });

        //点击减的按钮减1
        $scope.jian = function(index) {
            var id = $scope.product[index].id;

            $http.post("GoodsController/jian?id=" + id).success(
                    --$scope.product[index].account);
        };
        //点击加的按钮减1
        $scope.jia = function(index) {
            var id = $scope.product[index].id;

            $http.post("GoodsController/jia?id=" + id).success(
                    ++$scope.product[index].account);
        };

        //点击删除的按钮删除
        $scope.del = function(index) {
            var id = $scope.product[index].id;

            if (confirm("确认删除?")) {
                $http.post("GoodsController/Del?id=" + id).success(function() {
                    alert("删除成功");
                    location.reload();
                });
            }
        };

//点击输入框输入修改值数据库进行修改

        $scope.update = function(index) {
            var id = $scope.product[index].id;
            var account = $scope.product[index].account;
            alert(id);
            alert(account);
            $http.post("GoodsController/updateGoods?id=" + id + "&account="
                    + account);
        };

    });
</script>

 

</head>

<body ng-app="myapp">
    <div class="container" ng-controller="myController">
        <h1>欢迎进入购物车</h1>

        <table>
            <tr>
                <td><input type="checkbox"></td>
                <td>商品编号</td>
                <td>商品名称</td>
                <td>商品价格</td>
                <td>购买数量</td>
                <td>操作</td>

            </tr>

            <tr ng-repeat="p in product">
                <td><input type="checkbox" value="{{p.id}}"></td>
                <td>{{p.id}}</td>
                <td>{{p.goodsname}}</td>
                <td>{{p.price}}</td>

                <td>
                    <button class=" btn btn-success" value="{{p.id}}"
                        ng-click="jia($index)">+</button>
                        <input type="text"  ng-model="p.account" style="width: 30" value="{{p.account}}" ng-blur="update($index)">
                    
                    <button class=" btn btn-success" value="{{p.id}}"
                        ng-click="jian($index)">-</button>
                </td>
                <td><button class=" btn " ng-click="del($index)">删除</button></td>

            </tr>
        </table>

    </div>
</body>
    </html> </i>

转载于:https://my.oschina.net/u/3614502/blog/1522749

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值