EasyUI ---- draggable购物车
@{ ViewBag.Title = "Easyui_draggable"; Layout = "~/Views/Shared/Layouts.cshtml"; } <style type="text/css"> .products{ overflow:auto; height:100%; background:#fafafa; } .products ul{ list-style:none; margin:0; padding:0; } .products li{ display:inline; float:left; margin:10px; border:1px solid #ff0000; } .item{ display:block; text-decoration:none; } .item img{ width:100px; height:100px; } .cart { height:1000px; width:300px; float:right; } </style> <script type="text/javascript"> $(function () { $("#cartcontent").datagrid({ singleSelect:true,//单行选中 showFooter:true//显示页脚 }); }) $(".item").draggable({ revert: true,//如何使true,在拖动的元素会返回到其实位置 proxy: 'clone',//clone时,会复制一个元素 onStartDrag: function () { $(this).draggable('options').cursor = 'not-allowed'; $(this).draggable('proxy').css('z-index', 10); }, onStopDrag: function () { $(this).draggable('options').cursor = 'move'; } }); $(".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('RMB')[1])); } }); function addProduct(name,price) { var dg = $("#cartcontent"); var data = dg.datagrid('getData'); 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(); dg.datagrid('loadData', data); var cost = 0; var rows = dg.datagrid('getRows'); for (var i = 0; i < rows.length; i++) { cost += rows[i].price * rows[i].quantity; } dg.datagrid('reloadFooter', [{ name: '总计', price: cost }]); } </script> <h2>购物车</h2> <div class="easyui-panel" fit="true" border="false" style="height:100%;overflow:hidden"> <div class="cart"> <div class="ctitle">购物车</div> <div style="background:#fff"> <table id="cartcontent" fitColumns="true" style="width:250px; height:auto;"> <thead> <th field="name" width="140">商品名称</th> <th field="quantity" width="60">数量</th> <th field="price" width="60">价格</th> </thead> </table> </div> <div class="ctitle" style="position:absolute;bottom:40px">把商品拖到这里添加到购物车</div> </div> <div class="products"> <ul> <li> <a href="#" class="item"> <img src="~/Iamge/1.png" /> <div> <p>气球</p> <p>价格:RMB25</p> </div> </a> </li> <li> <a href="#" class="item"> <img src="~/Iamge/1.png" /> <div> <p>气球</p> <p>价格:RMB25</p> </div> </a> </li> <li> <a href="#" class="item"> <img src="~/Iamge/2.png" /> <div> <p>气球</p> <p>价格:RMB25</p> </div> </a> </li> <li> <a href="#" class="item"> <img src="~/Iamge/3.png" /> <div> <p>气球</p> <p>价格:RMB25</p> </div> </a> </li> </ul> </div> </div>
只能作参考,运行不起来。
分类:
EasyUI
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了