码迷,mamicode.com
首页 > 编程语言 > 详细

springboot+thymeleaf+mybatis逆向工程和pageHelper(3)

时间:2020-02-06 10:33:53      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:his   vertica   parent   inf   alt   span   cti   return   mamicode   

thymeleaf-+按钮:

  前端:

技术图片

  html:

                                        <td  style="vertical-align:middle" th:text="${product.price}"></td>
                                        <td  style="vertical-align:middle">
                                            <span style="margin:5px;padding-left:5px;padding-right: 5px;border:1.5px solid #ccc;" th:onclick="|javascript:jian(this,${product.id})|">-</span>
                                            <span th:text="${product.quantity}"></span>
                                            <span style="margin:5px;padding-left:5px;padding-right: 5px;border:1.5px solid #ccc;" th:onclick="|javascript:jia(this,${product.id})|">+</span>
                                        </td>

  js:

    //增加:
    function jia(obj,productId) {
        var button =$(obj);//表示当前按钮
        var numButton=button.prev();
        //获取购物车商品总额:
        var sumPricePre = button.parent().parent().children("td").eq(3);
        var sumPrice = sumPricePre[0].textContent;
        sumPrice = parseInt(sumPrice);
        var num=numButton.text();
        num=parseInt(num);
        //与数据库通信:
        //发送‘+‘的请求
        $.ajax({
            url:"/addShop/"+productId,
            success:function(data){
                if(data.trim()=="failed"){
                    alert("操作失败!");
                }else{
                    num++;
                    data = parseInt(data);
                    sumPrice+=data;
                    sumPricePre[0].textContent = sumPrice;
                    numButton.text(num);
                }
            }
        });
    }
    //减少:
    function jian(obj,productId){
        var button=$(obj);
        var numButton=button.next();
        var num=numButton.text();
        num=parseInt(num);

        //获取购物车商品总额:
        var sumPricePre = button.parent().parent().children("td").eq(3);
        var sumPrice = sumPricePre[0].textContent;
        sumPrice=parseInt(sumPrice);
        //得到单件商品的价格:
        var price = sumPrice/num;

        if(num==1){
            return;
        }

        $.ajax({
            url:"/reduceShop/"+productId,
            success:function(data){
                if(data.trim()=="failed"){
                    alert("操作失败!");
                }else{
                    num--;
                    sumPrice-=price;
                    sumPricePre[0].textContent = sumPrice;
                    numButton.text(num);
                }
            }
        });

    }

springboot+thymeleaf+mybatis逆向工程和pageHelper(3)

标签:his   vertica   parent   inf   alt   span   cti   return   mamicode   

原文地址:https://www.cnblogs.com/lyjblogg/p/12230607.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!