easyUI拖动购物车案例

<!DOCTYPE html><html><head>    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">    <meta name="keywords" content="jquery,ui,easy,easyui,web">    <title>拖动购物车案例</title>    <link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/default/easyui.css">    <link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/icon.css">    <script src="js/jquery.min.js" type="text/javascript"></script>    <script type="text/javascript" src="js/jquery-easyui/jquery.easyui.min.js"></script>    <style type="text/css">        .products{            list-style:none;            margin-right:300px;            padding:0px;            height:100%;        }        .products li{            display:inline;            float:left;            margin:10px;        }        .item{            display:block;            text-decoration:none;        }        .item img{            border:1px solid #333;        }        .item p{            margin:0;            font-weight:bold;            text-align:center;            color:#c3c3c3;        }        .cart{            position:fixed;            right:0;            top:0;            width:300px;            height:100%;            background:#ccc;            padding:0px 10px;        }        h1{            text-align:center;            color:#555;        }        h2{            position:absolute;            font-size:16px;            left:10px;            bottom:20px;            color:#555;        }        .total{            margin:0;            text-align:right;            padding-right:20px;        }    </style>    <script>        var data = {"total":0,"rows":[]};        var totalCost = 0;

$(function(){            $(‘#cartcontent‘).datagrid({                singleSelect:true            });            //拖动克隆的商品: draggable 属性的值从 ‘proxy‘ 设置为 ‘clone‘,所以拖动元素将由克隆产生。            $(‘.item‘).draggable({                revert:true,                proxy:‘clone‘,                onStartDrag:function(){                    $(this).draggable(‘options‘).cursor = ‘not-allowed‘;                    $(this).draggable(‘proxy‘).css(‘z-index‘,10);                },                onStopDrag:function(){                    $(this).draggable(‘options‘).cursor=‘move‘;                }            });

//放置选择商品到购物车中(购物车采用的是datagrid来存储)            $(‘.cart‘).droppable({                onDragEnter:function(e,source){                    $(source).draggable(‘options‘).cursor=‘auto‘;                },                onDragLeave:function(e,source){                    $(source).draggable(‘options‘).cursor=‘not-allowed‘;                },                onDrop:function(e,source){                    var name = $(source).find(‘p:eq(0)‘).html();                    var price = $(source).find(‘p:eq(1)‘).html();                    addProduct(name, parseFloat(price.split(‘$‘)[1]));                }            });        });

//每当放置商品的时候,需要首先得到商品名称和价格,然后调用 ‘addProduct‘ 函数来更新购物车。        function addProduct(name,price){            function add(){                for(var i=0; i<data.total; i++){                    var row = data.rows[i];                    if (row.name == name){                        row.quantity += 1;                        return;                    }                }                data.total += 1;                data.rows.push({                    name:name,                    quantity:1,                    price:price                });            }            add();            totalCost += price;            $(‘#cartcontent‘).datagrid(‘loadData‘, data);            $(‘div.cart .total‘).html(‘Total: $‘+totalCost);        }    </script></head><body style="margin:0;padding:0;height:100%;background:#fafafa;"><!--创建商品--><ul class="products">    <li>        <a href="#" class="item">            <img src="images/shirt1.gif"/>            <div>                <p>Balloon</p>                <p>Price:$25</p>            </div>        </a>    </li>    <li>        <a href="#" class="item">            <img src="images/shirt2.gif"/>            <div>                <p>Feeling</p>                <p>Price:$25</p>            </div>        </a>    </li>    <li>        <a href="#" class="item">            <img src="images/shirt3.gif"/>            <div>                <p>Elephant</p>                <p>Price:$25</p>            </div>        </a>    </li>    <li>        <a href="#" class="item">            <img src="images/shirt4.gif"/>            <div>                <p>Stamps</p>                <p>Price:$25</p>            </div>        </a>    </li>    <li>        <a href="#" class="item">            <img src="images/shirt5.gif"/>            <div>                <p>Monogram</p>                <p>Price:$25</p>            </div>        </a>    </li>    <li>        <a href="#" class="item">            <img src="images/shirt6.gif"/>            <div>                <p>Rolling</p>                <p>Price:$25</p>            </div>        </a>    </li></ul><!--创建购物车--><div class="cart">    <h1>Shopping Cart</h1>    <div style="background:#fff">        <table id="cartcontent" fitColumns="true" style="width:300px;height:auto;">            <thead>            <tr>                <th field="name" width=140>Name</th>                <th field="quantity" width=60 align="right">Quantity</th>                <th field="price" width=60 align="right">Price</th>            </tr>            </thead>        </table>    </div>    <p class="total">Total: $0</p>    <h2>Drop here to add to cart</h2></div></body></html>

原文地址:https://www.cnblogs.com/LindaBlog/p/9223739.html

时间: 2024-10-17 12:43:09

easyUI拖动购物车案例的相关文章

DOM操作相关案例 模态对话框,简易留言板,js模拟选择器hover,tab选项卡,购物车案例

1.模态框案例 需求: 打开网页时有一个普通的按钮,点击当前按钮显示一个背景图,中心并弹出一个弹出框,点击X的时候会关闭当前的模态框 代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> *{ padding: 0; margin: 0; }

easyUI拖动课程进课程表

<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>拖动课程表</title> <link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/default/easyui.css"> <link re

angularJS商品购物车案例

<!DOCTYPE html> <html ng-app="shopping"> <head lang="en"> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" href="bootstrap-3.3.4-dist/css/bootstrap.css"/

购物车案例 session

package com.cn.session; import java.io.IOException; import java.io.PrintWriter; import java.util.LinkedHashMap; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletR

vue界面初始化查询列表的方法之购物车案例

var vm = new Vue({ el:"#app", data:{ totalMoney:0, productList:[], checkAllFlag:false , delFlag:false delOneProduct:[], }, filters:{ //局部过滤器 ,调用方法{{number | formatMoney}} formatMoney:function(value){ return "$" +value.toFixed(2) //留两位小

vue界面初始化查询列表的方法之购物车案例-------支付界面

new Vue({ el:".container", data:{ addressList:[], limitNum:3, currentIndex:0, //用于选择地址,调用:class="{'check':index==currentIndex}" @click="currentIndex=index" shippingMethod:1,//使用见文档底部图片 }, mounted:function(){ this.$nextTick(fu

购物车案例

1.基本结构搭建 新建index.html.main.js.style.css 2.点击加减按钮,点击删除按钮删除列表,过滤器使用 原文地址:https://www.cnblogs.com/doumian/p/12147605.html

购物车的高级实现 逻辑结构清晰

HTML: 1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>购物车案例</title> 6 7 <style> 8 *{ 9 margin:10px; 10 font-family:"微软雅黑"; 11 color:#747474; 12 } 13 14 #header span { 15 d

购物车Demo,前端使用AngularJS,后端使用ASP.NET Web API(3)--Idetity,OWIN前后端验证

原文:购物车Demo,前端使用AngularJS,后端使用ASP.NET Web API(3)--Idetity,OWIN前后端验证 chsakell分享了前端使用AngularJS,后端使用ASP.NET Web API的购物车案例,非常精彩,这里这里记录下对此项目的理解. 文章:http://chsakell.com/2015/01/31/angularjs-feat-web-api/http://chsakell.com/2015/03/07/angularjs-feat-web-api-