简单实现拖动商品,加入购物车并总计商品的功能

<html>
<head>
<link rel="stylesheet" type="text/css" href="easyui.css">
<link rel="stylesheet" type="text/css" href="icon.css">
<script type="text/javascript" src="jquery-1.11.2.js"></script>
<script type="text/javascript" src="jquery.easyui.min.js"></script>
<script type="text/javascript">
	var data = {"total":0,"rows":[]};
	var totalCost = 0;

	$(function(){
		$(‘#cartcontent‘).datagrid({
			singleSelect:true
		});
		$(‘.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‘;
			}
		});
		$(‘.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]));
			}
		});

	});

	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>
<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>
</head>
<body>
	<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>Felling</p>
					<p>Price:$25</p>
				</div>
			</a>
		</li>
		<li>
			<a href="#" class="item">
				<img src="images/shirt3.gif"/>
				<div>
					<p>Balloon3</p>
					<p>Price:$25</p>
				</div>
			</a>
		</li>
		<li>
			<a href="#" class="item">
				<img src="images/shirt4.gif"/>
				<div>
					<p>Balloon4</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>
时间: 2024-07-29 13:06:32

简单实现拖动商品,加入购物车并总计商品的功能的相关文章

python(4)- 简单练习:python实现购物车的优化

简单版本,链接如下: http://www.cnblogs.com/c-x-m/p/7819220.html 购物车程序优化题目要求: 1. 用户退出时打印商品列表时,按以下格式 -------您购买的商品如下------ id    商品    数量    单价    总价 1      iPhone 2      5800     11400 2      coffee  1      30      30 ... 总计价格: 11430元 --------end -------------

电商网站中添加商品到购物车功能模块2017.12.8

前言: 电商网站中添加商品到购物车功能模块实现: 根据前一篇博客的介绍,我们看到淘宝网站为了保证购物车数据的同步,直接是强制用户必须登录才可以将商品加入购物车.而京东网站是用户在未登录的状态下也可以将商品加入到购物车,此时这个是保存在了cookie中,然后用户登录后,根据商品的id判断商品是否存在,将两个购物车的商品合并,形成最终的购物车商品. 本篇文章分两个模块,分别看下这两个功能是如何实现的: 1.必须在用户登录的前提下,才可以将商品加入到购物车列表 我们今天先看下淘宝网站的状态下的添加商品

简单的前端js+ajax 购物车框架(入门篇)

其实,一直想把自己写的一些js给总结下,也许是能力有限不能把它完美结合起来.只能自己默默的看着哪些代码,无能为力. 今天在公司实在没有事做,突然就想到写下商城的购物车的前端框架,当然我这里只有购物车的增删改查,也许写的并不是那么完善,但最重要的是一个入门,也希望js达人给些建议,好让我更上一个台阶. HOHO~~~开始咯: Js: //为了省事,就没写自己的js ajax了 用了jquery的,当然你也可以添加到jquery的扩展方法内,哈哈,我太懒了,所以就写这里了. var _$ = { A

写一个循环,不断的问客户想买什么 ,当用户选择一个商品编号,就把对应的商品加入购物车 ,最终用户输入q退出时,答应购物车的商品

写一个循环,不断的问客户想买什么 ,当用户选择一个商品编号,就把对应的商品加入购物车 ,最终用户输入q退出时,答应购物车的商品products=[["Iphone8",68888],["MacpPro",14800],["Coffee",31],["小米",2499],["Book",80],["Nlke",799]]shopping_cart=[]print(".....商品

添加商品到购物车add_to_cart.php

<?php session_start();//启动session $goods_id = $_POST['goods_id'];//获取商品id $number = $_POST['num'];//获取商品数量 if(empty($_SESSION["gwc"])) { //1.购物车是空的,第一次点击添加购物车 $arr[$goods_id] =array( 'goods_id' => $goods_id, 'num' => $number ); $_SESSIO

JAVA面向对象编程之购物车界面的设计与功能的实现

1.小组成员及分工 小组成员 负责工作 兰泽祥 负责总体界面.Git代码库 吴修恩 负责MVC模式.类名包名的规范化 2.Git 仓库地址 仓库地址:https://gitee.com/lanzexiang/shopping_cart.git 3.界面展示 ①登录界面 ②菜单界面 ③商城界面 ④商品搜索界面 ⑤购物车界面 ⑥订单界面 4.几个亮点功能介绍 1.购物车界面与订单界面 购物车界面与订单节单界面总体采用BorderLayout()布局,在BorderLayout()的中部使用CardL

非框架, 纯原生JS “商品详情跳转到商品列表,并记录高度“ 的写法思路

这里只讲思路,不提供代码. 写之前,我要先吐槽一种非常奇葩的写法.    下面是他的写法思路(虽不提倡,但可借鉴): 一个商品列表,然后把商品详情写在商品列表里. 这是一个页面,两个不一样的div标签,一个div标签是商品类表,另一个div标签是商品详情 从商品列表跳转到商品详情的操作是: 请求商品详情接口,请求到后赋值(在jq项目里特地引了个vue来双向绑定), 把当前页面的高度记录下来($document.scrollTop()获取高度), 然后把商品列表div标签隐藏掉,然后再显示商品详情

商品属性管理【把商品和属性关联起来】

在添加商品的表单中制作一个类型的下拉框 <!-- 商品属性 --> <table style="display:none;" width="90%" class="tab_table" align="center"> <tr><td> 商品类型: <?php buildSelect('Type','type_id','id','type_name'); ?> <

python爬虫之:淘宝商品搜索爬虫(收集商品信息/下载详情图)

一.获取商品信息: #!/usr/bin/python3.5 #coding:utf8 import xlsxwriter as wx import re import cgi import requests import os import time import urllib page=1 downsuccess = 0 downfaild = 0 shop = [("店铺名称","商品","商品售价¥","商品购买数",