一个很给力的js购物车程序

 

资源:http://simplecartjs.org/

文档相当齐全:http://simplecartjs.org/documentation/

、引入代码:

<script src="<{xoImgUrl jquery.1.6.1.min.js}>"></script>
	<!--cart-->
	<script src="<{xoImgUrl cart/test/qunit.js}>"></script>
	<script src="<{xoImgUrl cart/test/inject.js}>"></script>
	<script src="<{xoImgUrl cart/simpleCart.js}>"></script>
	<script>
	  simpleCart({
	    checkout: {
	      type: "SendForm",
	      url: "http://52taoyy.com/modules/pshow/cart/checkout"
            },
	    currency: "JPY"
	  });
	</script>

 

注意,jquery必需在1.6以上

、加入购物车代码:

<a class="linkCart" title="<{$pro.pro_name}>" οnclick="simpleCart.add({name:'<{$pro.pro_name}>', price: <{$pro.sales_price}>, image:'<{$pro.pro_photo1}>'}); alert('已经添加到购物车');"
						href="javascript:;">加入购物车</a>


、查看购物车

<div class="navtextbar">
	<a href="<{$xoops_url}>">首页</a> >> 我的购物车
</div>
<h4 class="">我的购物车</h4>
<style>
	.simpleCart_items table{
		border:1px solid #ccc;
	}
	.simpleCart_items th{
		color:#333;
		text-align:left;
		padding:10px 30px;
		border-bottom:1px solid #ccc;
		background: #ededed;
		background: -moz-linear-gradient(top,  #f7f7f7 0%, #ededed 100%);
		background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f7f7f7), color-stop(100%,#ededed));
		background: -webkit-linear-gradient(top,  #f7f7f7 0%,#ededed 100%);
		background: -o-linear-gradient(top,  #f7f7f7 0%,#ededed 100%);
		background: -ms-linear-gradient(top,  #f7f7f7 0%,#ededed 100%);
		background: linear-gradient(top,  #f7f7f7 0%,#ededed 100%);
		filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f7f7f7', endColorstr='#ededed',GradientType=0 );
	}
	.simpleCart_items td{
		padding:10px 30px;
		vertical-align:middle;
		border-bottom:1px solid #ccc;
		
	}
	.item-image,
	.item-image img{width:72px;}
	.item-name{width:50%;}
	.item-quantity,
	.item-quantity input{
		width:30px;
		text-align:center;
	}
	.item-price,
	.item-subtotal{width:50px;}
	.simpleCart_total_div{text-align:right; padding:5px; border-bottom:1px solid #ccc; font-size: 16px;}
	.simpleCart_total{margin-right: 20px;}
	.sp_left{float:left; margin-left: 10px;}
</style>
<div class="simpleCart_items">
	<!--数据加载前显示的内容 开始-->
	<div style="text-align:center;">购物车数据加载中...请稍待.
	<br /><img src="<{xoImgUrl icons/loading.gif}>" style="border:0px;"></div>
	<!--数据加载前显示的内容 结束-->
</div>	
<div class="simpleCart_total_div"><span class="sp_left"><a href='javascript:;'>前去结账</a></span>合计:<span class="simpleCart_total"></span></div>
<script>
	simpleCart({
		//Setting the Cart Columns for the sidebar cart display.
		cartColumns: [
			{ attr: "image", label: false, view: "image"},
			//Name of the item
			{ attr: "name" , label: "商品名称" },
			//Quantity displayed as an input
			{ attr: "quantity", label: "数量", view: "input"},
			//Built in view for a remove link
			{ view:"remove", text: "删除", label: false},
			//Price of item
			{ attr: "price", label: "单价"},
			//Subtotal of that row (quantity of that item * the price)
			{ attr: "total" , label: "小计", view: "currency"  }
		],
		cartStyle: "table",
		
	});
	
</script>


 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,编写购物车程序涉及到一些基本的 Android Studio 知识和 Java 编程知识。以下是一个简单的购物车程序的实现步骤: 1. 创建一个新的 Android Studio 项目,并在布局文件中添加一个 RecyclerView 组件作为购物车列表。 2. 创建一个 Item 类来表示购物车中的商品,包括商品名称、价格、数量等属性。 3. 创建一个 Adapter 类来连接购物车列表和 Item 数据。在 Adapter 中实现 RecyclerView.Adapter 的方法,包括 onCreateViewHolder、onBindViewHolder、getItemCount 等。 4. 在 MainActivity 中初始化购物车列表和 Adapter,并将 Adapter 设置为 RecyclerView 的适配器。 5. 实现添加商品功能。可以通过一个按钮或者其他交互方式触发添加商品的操作,向 Item 数据中添加一个新的 Item 对象,然后调用 Adapter 的 notifyItemInserted 方法更新 RecyclerView。 6. 实现删除商品功能。在 Item 数据中移除指定的 Item 对象,然后调用 Adapter 的 notifyItemRemoved 方法更新 RecyclerView。 7. 实现修改商品数量功能。在 Item 数据中更新指定 Item 对象的数量属性,然后调用 Adapter 的 notifyItemChanged 方法更新 RecyclerView。 8. 实现计算购物车总价功能。遍历 Item 数据,累加每个商品的价格和数量,得出购物车的总价。 以上是一个简单的购物车程序的实现步骤,具体实现细节需要根据具体需求进行调整。希望对您有帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值