多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

中國(guó)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2

jqueryeasyui教程

jQuery EasyUI 教程

jEasyUI 應(yīng)用

jEasyUI 拖放

jEasyUI 菜單與按鈕

jEasyUI 布局

jEasyUI 數(shù)據(jù)網(wǎng)格

jEasyUI 窗口

jEasyUI 樹(shù)形菜單

jEasyUI 表單

jEasyUI 參考手冊(cè)

jQuery EasyUI 拖放 – 創(chuàng)建拖放的購(gòu)物車

閱讀 (2377)

jQuery EasyUI 拖放 - 創(chuàng)建拖放的購(gòu)物車

如果您能夠通過(guò)您的 Web 應(yīng)用簡(jiǎn)單地實(shí)現(xiàn)拖動(dòng)和放置,您就會(huì)知道一些特別的東西。通過(guò) jQuery EasyUI,我們?cè)?Web 應(yīng)用中可以簡(jiǎn)單地實(shí)現(xiàn)拖放功能。

在本教程中,我們將向您展示如何創(chuàng)建一個(gè)啟用用戶拖動(dòng)和放置用戶想買的商品的購(gòu)物車頁(yè)面。購(gòu)物籃中的物品和價(jià)格將更新。

顯示頁(yè)面上的商品

	<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>
		<!-- other products -->
	</ul>

正如您所看到的上面的代碼,我們添加一個(gè)包含一些 <li> 元素的 <ul> 元素來(lái)顯示商品。所有商品都有名字和價(jià)格屬性,它們包含在 <p> 元素中。

創(chuàng)建購(gòu)物車

	<div class="cart">
		<h1>Shopping Cart</h1>
		<table id="cartcontent" 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>
		<p class="total">Total: $0</p>
		<h2>Drop here to add to cart</h2>
	</div>

我們使用數(shù)據(jù)網(wǎng)格(datagrid)來(lái)顯示購(gòu)物籃中的物品。

拖動(dòng)克隆的商品

	$('.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';
		}
	});

請(qǐng)注意,我們把 draggable 屬性的值從 'proxy' 設(shè)置為 'clone',所以拖動(dòng)元素將由克隆產(chǎn)生。

放置選擇商品到購(gòu)物車中

	$('.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]));
		}
	});
	var data = {"total":0,"rows":[]};
	var totalCost = 0;
	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); 	}	 

每當(dāng)放置商品的時(shí)候,我們首先得到商品名稱和價(jià)格,然后調(diào)用 'addProduct' 函數(shù)來(lái)更新購(gòu)物籃。

下載 jQuery EasyUI 實(shí)例

jeasyui-dd-shopping.zip

關(guān)閉
程序員人生
主站蜘蛛池模板: 三级不卡视频 | 欧美不卡视频在线 | 亚洲国产成人久久笫一页 | 噜噜噜在线视频免费观看 | 欧美日韩第一页 | 伊人久久大香线蕉综合网站 | 日本免费区 | 成人亚洲天堂 | 国产中文欧美 | 精品国产一区二区三区2021 | 中文字幕a∨在线乱码免费看 | 麻豆精品不卡国产免费看 | 亚洲区在线播放 | 尤物视频在线看 | 午夜www | 伊人影院在线视频 | 欧洲vodafonewifi一区 | 亚洲精品美女国产一区 | 欧美春色| 国产女人精品性视频 | a级片在线免费看 | 日本香蕉一区二区在线观看 | www羞羞动漫网在线观看 | 伊人狼人影院 | xxxwww欧美性| 校园春色欧美激情 | 校园春色亚洲激情 | 国产日韩欧美综合一区 | 国产成人 免费观看 | 亚洲免费在线观看视频 | 乌克兰xxxx | 国产精品欧美日韩 | 尤物 在线播放 | 性欧美孕妇xxxx | 最近2019中文字幕免费看最新 | 国产suv精品一区二区四区三区 | 午夜免费啪在线观看视频网站 | 亚洲欧美视频一区 | 另类图片 亚洲 校园 小说区 | 波多野结衣久久精品免费播放 | 一级女性全黄久久生活片免费 |