當前位置:首頁 » 網購平台 » jquery點擊加入購物車
擴展閱讀
寧波奧德賽優惠價格 2021-03-15 14:26:02
丹尼斯購物卡能掛失么 2021-03-15 14:25:58
淘寶購物指紋驗證失敗 2021-03-15 14:24:44

jquery點擊加入購物車

發布時間: 2021-02-27 12:07:03

『壹』 類似淘寶加入購物車的插件,可以點擊加入購物車以後,圖標會跳躍的加入下方,和獵豹下載一樣的效果,

尊敬的金山網路用戶,您好!
樓主不知道遇到了什麼問題,能否解釋下?

希望可以幫到您!

『貳』 jquery 彈出框,如下圖 ,加入購物車效果

<!DOCTYPEhtml>

<htmllang="en"xmlns="http://www.w3.org/1999/xhtml">
<head>
<metacharset="utf-8"/>
<title></title>
<scripttype="text/javascript"src="jquery.min.js"></script>
<styletype="text/css">
.des{
width:400px;
margin:0auto;
}

.add2carttip{
width:220px;
height:90px;
padding:0;
border:1pxsolidrgba(69,66,66,0.91);
background-color:#393939;
margin:0auto;
border-radius:12px12px;
position:fixed;
display:none;
}

.add2carttip>div{
vertical-align:middle;
color:#D0D0D0;
text-align:center;
font-size:1.2em;
font-weight:bold;
margin:0;
}

.c-title{
height:39px;
line-height:39px;
border-bottom:1px#D0D0D0solid;
}

.c-content{
height:49px;
line-height:49px;
border-top:1px#D0D0D0solid;
}

.c-add,.c-sub{
display:inline-block;
vertical-align:middle;
width:20px;
font-size:1.5em;
font-weight:bold;
cursor:pointer;
}

.c-sub{
vertical-align:-5px;
font-size:1.8em;
}

.c-count{
width:30px;
height:30px;
border-radius:15px;
border:none;
text-align:center;
font-size:inherit;
}

.c-action{
display:inline-block;
cursor:pointer;
}

.c-add:hover,.c-sub:hover,.c-action:hover{
color:#FAFAFA;
}
</style>
<scripttype="text/javascript">
$(function(){
var$tip=$('.add2carttip');
var$add=$('.c-add');
var$sub=$('.c-sub');
var$count=$('.c-count');
var$action=$('.c-action');

var$win=$(window);

functionsetTipPosition(){
$tip.animate({
left:(($win.width()-$tip.width())/2)+'px',
top:($win.height()*1/3)+'px'
},500);
}
setTipPosition();
$win.on('resize',setTipPosition);

$tip.on('selectstart',function(e){e.preventDefault();returnfalse;});

$add.on('click',function(){
$count.val(parseInt($count.val())+1);
});
$sub.on('click',function(){
$count.val(parseInt(($count.val())-1)||1);
});
$action.on('click',function(){
alert('add'+$count.val()+'tocart.');
});
$('.toggleTip').on('click',function(){
$tip.fadeToggle(500);
});
});
</script>

</head>
<body>
<divclass="des">
不支持IE9以下的IE瀏覽器
<ahref="javascript:void();"class="toggleTip">顯示或隱藏</a>
</div>
<divclass="add2carttip">
<divclass="c-title">
商品詳情
</div>
<divclass="c-content">
<spanclass="c-add">+</span>
<inputtype="text"class="c-count"value="1"/>
<spanclass="c-sub">-</span>
<spanclass="c-action">
加入購物車
</span>
</div>
</div>
</body>
</html>

代碼 。。。

『叄』 jquery 實現加入購物車功能

參考以下代碼:

注意需要導入.js.

<!DOCTYPEhtml>
<html>
<head>
<title>購物車----jQuery</title>
<metacharset="utf-8"/>
<styletype="text/css">
h1{
text-align:center;
}
table{
margin:0auto;
width:60%;
border:2pxsolid#aaa;
border-collapse:collapse;
}
tableth,tabletd{
border:2pxsolid#aaa;
padding:5px;
}
th{
background-color:#eee;
}
</style>
<scripttype="text/javascript"src="./js/jquery.js"></script>
<scripttype="text/javascript">
functionadd_shoppingcart(btn){//將btn(dom)轉換為jQuery對象
//先獲取商品名字和單價還有庫存以備後面使用
var$tds=$(btn).parent().siblings();
//$tds.eq(0)是jQuery對象$tds[0]是DOM對象
varname=$tds.eq(0).html();//string
varprice=$tds.eq(1).html();//string
varstock=$tds.eq(3).html();//string

//查看庫存是否還有<=0
if(stock<=0){
return;
}

//無論購物車中是否有該商品,庫存都要-1
$tds.eq(3).html(--stock);

//在添加之前確定該商品在購物車中是否存在,若存在,則數量+1,若不存在則創建行
var$trs=$("#goods>tr");
for(vari=0;i<$trs.length;i++){
var$gtds=$trs.eq(i).children();
vargName=$gtds.eq(0).html();
if(name==gName){//若存在
varnum=parseInt($gtds.eq(2).children().eq(1).val());
$gtds.eq(2).children().eq(1).val(++num);//數量+1
//金額從新計算
$gtds.eq(3).html(price*num);
return;//後面代碼不再執行
}
}
//若不存在,創建後追加
varli=
"<tr>"+
"<td>"+name+"</td>"+
"<td>"+price+"</td>"+
"<tdalign='center'>"+
"<inputtype='button'value='-'onclick='decrease(this);'/>"+
"<inputtype='text'size='3'readonlyvalue='1'/>"+
"<inputtype='button'value='+'onclick='increase(this);'/>"+
"</td>"+
"<td>"+price+"</td>"+
"<tdalign='center'>"+
"<inputtype='button'value='x'onclick='del(this);'/>"+
"</td>"+
"</tr>";
//追加到#goods後面
$("#goods").append($(li));

//總計功能
total();
}

//輔助方法--單擊購物車中的"+""-""x"按鈕是找到相關商品所在td,以jQuery對象返回
functionfindStock(btn){
varname=$(btn).parent().siblings().eq(0).html();//獲取商品名字
//注意table默認有行分組,若此處使用$("#table1>tr:gt(0)")則找不到任何tr
var$trs=$("#table1>tbody>tr:gt(0)");
for(vari=0;i<$trs.length;i++){
varfName=$trs.eq(i).children().eq(0).html();
if(name==fName){//找到匹配的商品
return$trs.eq(i).children().eq(3);
}
}
}

//增加"+"功能
functionincrease(btn){
//獲取該商品庫存看是否<=0
var$stock=findStock(btn);
varstock=$stock.html();
if(stock<=0){
return;
}
//庫存-1
$stock.html(--stock);
//購物車數據改變
var$td=$(btn).prev();
varnum=parseInt($td.val());//number
//num此時為number類型(在計算時會自動轉換為number類型)
$td.val(++num);
//獲取單價,再加計算前要先轉換為number類型
varprice=parseInt($(btn).parent().prev().html());
$(btn).parent().next().html(num*price);

//總計功能
total();
}

//減少"-"功能
functiondecrease(btn){
//該商品數量=1時候不能再減少
varnum=parseInt($(btn).next().val());
if(num<=1){
return;
}
var$stock=findStock(btn);
//庫存+1
varstock=$stock.html();
$stock.html(++stock);
//商品數量-1
$(btn).next().val(--num);
//從新計算金額
varprice=parseInt($(btn).parent().prev().html());
$(btn).parent().next().html(price*num);

//總計功能
total();
}

//"x"刪除按鈕功能
functiondel(btn){
//將商品數量歸還庫存
var$stock=findStock(btn);
varstock=parseInt($stock.html());
varnum=parseInt($(btn).parent().prev().prev().children().eq(1).val());
$stock.html(num+stock);
//清空改行商品列表
$(btn).parent().parent().remove();

//總計功能
total();
}
//總計功能
functiontotal(){
//獲取所有購物車中的trs
var$trs=$("#goodstr");
varamount=0;
for(vari=0;i<$trs.length;i++){
varmoney=parseInt($trs.eq(i).children().eq(3).html());
amount+=money;
}
//寫入總計欄
$("#total").html(amount);
}
</script>
</head>
<body>
<h1>真劃算</h1>
<tableid="table1">
<tr>
<th>商品</th>
<th>單價(元)</th>
<th>顏色</th>
<th>庫存</th>
<th>好評率</th>
<th>操作</th>
</tr>
<tr>
<td>羅技M185滑鼠</td>
<td>80</td>
<td>黑色</td>
<td>5</td>
<td>98%</td>
<tdalign="center">
<inputtype="button"value="加入購物車"onclick="add_shoppingcart(this);"/>
</td>
</tr>
<tr>
<td>微軟X470鍵盤</td>
<td>150</td>
<td>黑色</td>
<td>9028</td>
<td>96%</td>
<tdalign="center">
<inputtype="button"value="加入購物車"onclick="add_shoppingcart(this);"/>
</td>
</tr>
<tr>
<td>洛克iphone6手機殼</td>
<td>60</td>
<td>透明</td>
<td>672</td>
<td>99%</td>
<tdalign="center">
<inputtype="button"value="加入購物車"onclick="add_shoppingcart(this);"/>
</td>
</tr>
<tr>
<td>藍牙耳機</td>
<td>100</td>
<td>藍色</td>
<td>8937</td>
<td>95%</td>
<tdalign="center">
<inputtype="button"value="加入購物車"onclick="add_shoppingcart(this);"/>
</td>
</tr>
<tr>
<td>金士頓U盤</td>
<td>70</td>
<td>紅色</td>
<td>482</td>
<td>100%</td>
<tdalign="center">
<inputtype="button"value="加入購物車"onclick="add_shoppingcart(this);"/>
</td>
</tr>
</table>

<h1>購物車</h1>
<table>
<thead>
<tr>
<th>商品</th>
<th>單價(元)</th>
<th>數量</th>
<th>金額(元)</th>
<th>刪除</th>
</tr>
</thead>
<tbodyid="goods">
</tbody>
<tfoot>
<tr>
<tdcolspan="3"align="right">總計</td>
<tdid="total"></td>
<td></td>
</tr>
</tfoot>
</table>
</body>
</html>

最終效果圖:

『肆』 Jquery商品拋物線飛入購物車代碼

這個建議你去找現成js。。給你提供一個地址。。

http://www.zhangxinxu.com/wordpress/?p=3855

裡面有現成的方法。。



張鑫專旭同學的博客屬裡面有這樣的方法。。你可以去找的。

zhangxinxu.com/study/201312/js-parabola-shopping.html

就是這個地址啦。跟你這個一樣的效果

『伍』 如何用jquery實現購物車加減

直接刪除就是了。不過現在都在賽客寶貝街購物。正品,選擇多。

『陸』 有沒有添加購物車的代碼 JavaScript 或者jquery 的都可以

添加購物車需要和伺服器端進行數據交互,前端主要是用js的ajax功能將產品的id或者其他信息提交給伺服器端,然後等伺服器端返回添加成功,再在頁面上的購物車中增加添加的商品。

『柒』 關於jQuery,想要實現一個類似於購物車的功能。但是在將商品添加了以後,無法在購物車中刪除,請問和解

因為second中初始是沒有li的,所以點擊事件沒注冊上去,應改為:
$("#second li").live("click", function() {
$(this).remove();

});

『捌』 加入購物車 jquery怎麼實現

兩種辦法,一種是存到cookie,一種是存到資料庫。淘寶的購物車,是存到資料庫的。

『玖』 很奇怪的js,ajax的問題,關於添加到購物車及點擊刪除的,就類似京東商城的那樣。

初步懷疑你的刪除事件綁定有問題:新加入的DOM元素未綁定到事件。這種情況版應該使用事件委派來做,權你用 jQuery 嗎?假設你的購物車列表的 HTML 結構如下:

<ulid="cartList">
<li>
購物車商品1
<button>刪除</button>
</li>
<li>
購物車商品2
<button>刪除</button>
</li>
……
</ul>

則刪除購物車商品的代碼為(用了 jQuery):

$('#cartList').on('click','button',function(){//委派button的點擊事件
$(this).parent().remove();//移除購物車里當前商品
});

『拾』 jquery實現添加到購物車拖放功能 像百度旅遊定製旅遊一樣 如下圖

這功能網路內部有專門開發的。
拖拉帶拽的功能你可以看下jquery ui,裡面有部分功能可以拖動和獲取的,這功能要實現,代碼會有點復雜。
你先自己搜搜看吧