❶ 用python怎麼實現購物車的加減功能
1、利用selenium控制瀏覽器實顫虧棚現搶購加減功能,用此庫模擬用戶從打開瀏覽器到加入購物車提交訂單付款的過程即可實現搶購優點是簡單方便,缺點是速度慢和受網速影響較大。
2、用Requests庫茄則,模擬提交瀏覽器到伺服器的數據,瀏覽器在開發者模式界面看到每一次請求的具體信息,把這些信息通過此庫發送到伺服器也可實現搶購加減功能,優點是速度快,缺點是復雜,容易被識別反空羨爬蟲。
❷ jquery實現購物車物品加減 沒效果,求解
你選擇器取錯了,沒取到兩個按鈕:
注意看,#是 id選擇器,class選擇器是以「.」開頭的。
你的代碼裡面 加減兩個按鈕的 id分別為:add1 和 min1 而它們的class為: add和min
所以正確的做法是
$("#add") ---> $("#add1") 、 $("#min") ---> $("#min1")
或者
$("#add") ---> $(".add") 、 $("#min") ---> $(".min")
有不明白的歡迎追問^_^
❸ ecshop購物車加減css樣式代碼怎麼樣添加
在style.css里添加下面樣式
.goods_cut{
background:url("../images/plus.gif")no-repeatscroll00transparent;
border:0none;
cursor:pointer;
display:block;
float:left;
font-size:0;
height:15px;
line-height:0;margin:8px3px0;
width:15px;
}
input.goodsBuyBox,input.number{
border:1pxsolid#DDDDDD;
float:left;
font-size:10px;
height:18px;
line-height:18px;
margin:5px6px0;
padding:0;
text-align:center;
width:32px;
}
.goods_add{
background:url("../images/plus.gif")轎腔no-repeatscroll0-15pxtransparent;
border:0none;
cursor:pointer;
display:block;
float:left;
font-size:0;
height:15px;
line-height:0;
margin:8px3px0;
width:15px;
}
在flow.dwt里,看各自的模板去修改,總之要找到這串代碼:
<input type="text" name="goods_number[{$goods.rec_id}]" ……
下面是腳本,放進flow.dwt里
<scriptlanguage="javascript"type="text/javascript">
functiongoods_cut($val){
varnum_val=document.getElementById('number'+$val);
varnew_num=num_val.value;
if(isNaN(new_num)){alert('請輸入前散數字');returnfalse}
varNum=parseInt(new_num);
if(Num>1)Num=Num-1;
num_val.value=Num;
慧帆氏document.getElementById('updatecart').click();
}
functiongoods_add($val){
varnum_val=document.getElementById('number'+$val);
varnew_num=num_val.value;
if(isNaN(new_num)){alert('請輸入數字');returnfalse}
varNum=parseInt(new_num);
Num=Num+1;
num_val.value=Num;
document.getElementById('updatecart').click();
}
</script>
找到
<input type="text" name="goods_number[{$goods.rec_id}]"
搜索不到你就搜goods_number就行了
替換為:
<spanclass="goods_cut"onclick="goods_cut('{$goods.rec_id}');"></span>
<inputtype="text"name="goods_number[{$goods.rec_id}]"id="number{$goods.rec_id}"value="{$goods.goods_number}"size="4"class="number"onblur="if(isNaN(this.value)){alert('請輸入數字');returnfalse}else{document.getElementById('updatecart').click();}"title="{$lang.goods_number_tip}"/>
<spanclass="goods_add"onclick="goods_add('{$goods.rec_id}');"></span>
找到
<input name="submit" type="submit" value="{$lang.update_cart}" class="btn_s3"/>
其實就是更新購物車的按鈕
添加一個id=「updatecart」
<input name="submit" type="submit" id="updatecart" value="{$lang.update_cart}" class="btn_s3"/>
❹ 請教一個問題! /** * 購物車加減按鈕 ,現在第一個數據可以,後面的不可以!
我能說我真的不會么
❺ 如何用axure做出購物車數量加減,看了你就知道
(1)首先建立一個空白頁面,然後畫出一個大矩形,兩個數量加減的小矩形(分別命名為「+」「-」,可以填充一下碰悄顏色),最後畫一個實現數量加減的文察吵山本框,命名為「數量」.如圖所示。
(2)首先選中「-」號矩形,在屬性里給它添加事件,滑鼠單擊時,如圖所示。
(3)點擊設置文本,在窗口右邊選擇我們要實現效果的元件,也就是「數量」,如圖所示。
(4)點擊窗口右下方設置文本值裡面的fx,插入函數,如圖所示。
(5)點擊添加局部變數,為變數命名,我們取名為num(可自定義),第二個選擇元件文字,第三個選擇我們命名的「數量」,在插入變數與函數里輸入 [[num-1]],點擊確定。如圖所示。
(6)我們的「-」就做好了但是購物車數量可不能為負數哦,所以要給他設置條件,點擊添加條件,給它設置條件,點擊確定,如圖所示。
(7)「+」的效果,依照2-4步,(5)步在敗中插入變數與函數里輸入 [[num+1]],點擊確定。如圖所示。
(8)這樣我們一個利用AXURE就做出了一個單擊「+」「-」按鈕,實現購物車數量加減的效果了。
❻ ecshop 修改購物車中的購物數量,代碼如下,為什麼點擊加減圖片沒有得到相應的效果呢急。。。
這樣,我給你一段這個代碼,你相對比一下看看
<li style="width:608px"> <div class="guige" style="width:220px; float:left;">
<script language="javascript" type="text/javascript"> function goods_cut(){ var num_val=document.getElementById('number'); var new_num=num_val.value; var Num = parseInt(new_num); if(Num>1)Num=Num-1; num_val.value=Num; } function goods_add(){ var num_val=document.getElementById('number'); var new_num=num_val.value; var Num = parseInt(new_num); Num=Num+1; num_val.value=Num; } </script>
<span class="shuliang" style="width:165px">購買數量:<a href="javascript:void(0)" onclick="goods_cut();changePrice();">-</a><input onblur="changePrice();" id="number" name="" value="1" type="text"><a href="javascript:void(0)" onclick="goods_add();changePrice();">+</a></span></div>
<div style="float:left; width:150px;" >{$lang.amount}:<strong id="ECS_GOODS_AMOUNT" style="font-size:16px; font-weight:bold; color:#F34761;"></strong></div>
</li>
❼ jquery問題購物車加減按鈕
因為一個頁面中只能存在一個 id 為 add 的元素,根據你現在的代碼,如果有10行記錄,那就會有10個 id 為 add 的 input。
所以你要把這些 input 的 id 都改為 class,text_box 的值也要根據每次點擊來判斷
<input class="min" name="" type="button" value="-" />
<input class="text_box" name="goodnum" type="text" value="${item.value.quantity }" style="width:25px;" />
<input class="add" name="" type="button" value="+" />
$(".add").click(function() {
// $(this).prev() 就是當前元素的前一個元素,即 text_box
$(this).prev().val(parseInt($(this).prev().val()) + 1);
setTotal();
});
$(".min").click(function() {
// $(this).next() 就是當前元素的下一個元素,即 text_box
$(this).next().val(parseInt($(this).next().val()) - 1);
setTotal();
});
❽ 求php增加購物車數量的加減,
偽代碼:
前端:在你頁面上數量那欄增加
<div class="quantity-form"><a href="javascript:void(0);" clstag="cart_num_down" class="decrement disabled" id="decrement_8888_526830_1_1">-</a>
<input autocomplete="off" type="text" class="itxt" value="1" id="changeQuantity_8888_526830_1_1_0" minnum="1">
<a href="javascript:void(0);" clstag="cart_num_up" class="increment" id="increment_8888_526830_1_1_0">+</a>
</div>
你的購物車是個循環列表,可以去得到,每個商品的信息:id是商品
function cart_num_up(id,uid){
$.ajax({
type: "POST",
url: "CART_num.PHP",
data: {id:id, num:-1,uid:uid},
dataType: "json",
success: function(data){
if(data.status==1){
});
});
}
function cart_num_down(id,uid){
$.ajax({
type: "POST",
url: "CART_num.PHP",
data: {id:id, num:1,uid:uid},
dataType: "json",
success: function(data){
if(data.status==1){
});
});
}
點一次 加或減按鈕,觸發js向後端發起ajax請求:返回的是增加成功和失敗狀態和剩餘數量;
CART_num.PHP
$id = (int)$_POST['id'];
$num = (int)$_POST['num'];
$uid =(int)$_POST['uid']; //有封裝獲取post或get函數更好
//查庫看庫存
$sort = get_kucun_num();
//查看購物車目前數量
$cart_num = get_cart_num(uid,id);
//判斷庫存
if($sort >$cart_num){
}else{
}
if($num<0){
//減法 $sql =「update cart set cart_num = cart_num-1 where uid =uid and id =id 」
if(($cart_num-1)>1){
}else{
}){
//加法 $sql =「update cart set cart_num = cart_num+1 where uid =uid and id =id 」
}else{
//不正確的請求
}
❾ 購物車滿100減2元,200減5元 300減7元,php這個代碼怎麼寫,腦殼都想破了。
$count_price = 多少錢;//購物車總金額
if($count_price >=100 && $count_price<200)
{
$count_price = $count_price-2;
}else if($count_price>=200 && $count_price<300){
$count_price = $count_price -5;
}else if($count_price>=300){
$count_price = $count_price - 7;
}
❿ 用html做一個購物車,能實現簡單的產品數量和價格的加減就行。最後能計算出提交物品價格的總和。
html中的購物車的增減不能直接傳送到後台,可以通過ajax,在js中發送ajax
純前端的話可以參考下面的
<!DOCTYPEhtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>cart</title>
<styletype="text/css">
body,p,a,input{
margin:0;
padding:0;
font-size:12px;
}
.container{
width:100%;
}
.main{
width:1000px;
height:500px;
margin:100pxauto;
}
.main.cart-containertable{
width:100%;}
.main.cart-containertabletr{
text-align:center;
}
.main.cart-containertabletr:hover{
background:rgba(128,128,128,0.2);
}
.main.cart-containertable.table-header{
height:30px;
background:#d9d9d9;
font-size:1.2em;
}
.main.cart-containertable.table-headertd:first-child{
border-left:solid4pxred;
box-sizing:border-box;
}
.main.cart-containertabletrtd:nth-child(1),
.main.cart-containertabletrtd:nth-child(2){
text-align:left;
}
.main.cart-containertabletrtd:nth-child(2){
width:52%;
}
.main.cart-containertabletrtd:nth-child(3){
width:12%;
}
.main.cart-containertabletrtd:nth-child(4){
width:12%;
}
.main.cart-containertabletrtd:nth-child(5){
width:12%;
}
.main.cart-containertabletrtd:last-child{
width:10%;
}
.cart-good{
height:60px;
}
.cart-goodimg{
float:left;
margin:10px;
width:60px;
}
.cart-goodtdp{
margin:10px0px;
}
/*加、減按鈕*/
.cart-goodtdinput[type='button']{
width:20px;
height:20px;
background:#00f300;
outline:none;
border:none;
}
.cart-goodtdinput[type='button']:disabled{
background:grey;
}
.cart-goodtdinput[type='button']:first-child{
margin-right:-4px;
}
.cart-goodtdinput[type='button']:last-child{
margin-left:-4px;
}
.cart-goodtdinput[type='text']{
width:30px;
height:20px;
outline:none;
border:none;
text-align:center;
}
.table-footer{
display:flex;
justify-content:space-between;
line-height:40px;
}
.table-footerdiv{
font-size:1.2em;
}
.table-footerdivbutton{
background:red;
width:120px;
height:40px;
color:white;
}
</style>
</head>
<body>
<divclass="container">
<header></header>
<sectionclass="main">
<divclass="cart-container">
<tablecellspacing="0">
<trclass="table-header">
<td><inputtype="checkbox"id="chk_alla"></td>
<td>聚美優品發貨</td>
<td>聚美價</td>
<td>數量</td>
<td>小計</td>
<td>操作</td>
</tr>
<!--<trclass="cart-good">-->
<!--<td><inputtype="checkbox"id="001"></td>-->
<!--<td>-->
<!--<imgsrc="https://p2.jmstatic.com/proct/001/293/1293263_std/1293263_60_60.jpg"alt="">-->
<!--<p>[極速免稅]PITTAMASK口罩3枚入</p>-->
<!--<p>型號:新版防曬款容量:3枚入</p>-->
<!--</td>-->
<!--<td>89.00</td>-->
<!--<td>-->
<!--<inputtype="button"value="-">-->
<!--<inputtype="text"value="1">-->
<!--<inputtype="button"value="+">-->
<!--</td>-->
<!--<td>89.00</td>-->
<!--<td><ahref="#">刪除</a></td>-->
<!--</tr>-->
</table>
<divclass="table-footer">
<div>
<inputtype="checkbox"id="chk_allb"><labelfor="chk_allb">全選</label>
<spanstyle="margin-left:20px">繼續購物|清空選中商品</span>
</div>
<div>
共<spanid="good_count">5</span>件商品商品應付總額:<spanid="goods_total">¥229.00</span>
<buttonclass="btn_menu">去結算</button>
</div>
</div>
</div>
</section>
</div>
<script>
(function(){
varskin_procts=[
{
"id":"002",
"title":"EsteeLauder多效智妍精華霜15ml",
"img_url":"http://p0.jmstatic.com/proct/003/565/3565880_std/3565880_350_350.jpg",
"price":249.0,
"number":6,
"acount":"520",
"ischecked":true
},
{
"id":"004",
"title":"EsteeLauder肌透修護潔面乳30ml",
"img_url":"http://p4.jmstatic.com/proct/003/155/3155764_std/3155764_350_350.jpg",
"price":49.9,
"number":1,
"acount":"5911",
"ischecked":false
},
{
"id":"008",
"title":"雅詩蘭黛無痕持妝粉底液",
"img_url":"http://p3.jmstatic.com/proct/003/662/3662318_std/3662318_350_350.jpg",
"price":69.9,
"number":2,
"acount":"3972",
"ischecked":true
},
{
"id":"0012",
"title":"EsteeLauder肌初賦活原生液30ml",
"img_url":"http://p4.jmstatic.com/proct/003/565/3565914_std/3565914_350_350.jpg",
"price":159.0,
"number":1,
"acount":"2338"
},
{
"id":"001",
"title":"雅詩蘭黛無痕持妝粉底液30ml",
"img_url":"http://p2.jmstatic.com/proct/001/648/1648502_std/1648502_350_350.jpg",
"price":298.0,
"number":4,
"acount":"5071",
"ischecked":false
},
{
"id":"009",
"title":"雅詩蘭黛眼部精華霜15ml",
"img_url":"http://p1.jmstatic.com/proct/001/049/1049746_std/1049746_350_350.jpg",
"price":399.0,
"number":1,
"acount":"4022",
"ischecked":false
}
]
//添加商品
functionload(){
vartbody=document.querySelector('.cart-containertabletbody');
for(letgoodofskin_procts){
tbody.innerHTML+=`<trclass="cart-good"id="${good.id}">
<td><inputtype="checkbox"class="good-check"${good.ischecked?"checked":''}></td>
<td>
<imgsrc="${good.img_url}"alt="">
<p>[極速免稅]PITTAMASK口罩3枚入</p>
<p>型號:新版防曬款容量:3枚入</p>
</td>
<td>${good.price}</td>
<td>
<inputtype="button"value="-"${good.number<=1?"disabled":''}>
<inputtype="text"value="${good.number}">
<inputtype="button"value="+">
</td>
<td>${good.price*good.number}</td>
<td><ahref="#">刪除</a></td>
</tr>`
}
totalAcount();
}
load();
//endall..........
//1.為table注冊單擊事件
vartable01=document.querySelector('.cart-containertable');
table01.onclick=function(event){
varnode=event.target
if(node.getAttribute('type')=='button'){
//alert(event.target.value);
changeNumber(event);
subtotal(event);
checkedRow(event);
checkedAllRows();
}elseif(node.className=='good-check'){
checkedAllRows();
}elseif(node.id=='chk_alla'){
varf=event.target.checked;
varchks=document.querySelectorAll('.good-check');
for(varckofchks){
ck.checked=f;
}
for(vargoodofskin_procts){
good.ischecked=f;
}
}elseif(node.nodeName.toLowerCase()=='a'){
vartr=event.target.parentNode.parentNode;
for(vari=0;i<skin_procts.length;i++){
if(skin_procts[i].id==tr.id){
skin_procts.splice(i,1);
console.log(skin_procts);
}
}
tr.parentNode.removeChild(tr);
}
totalAcount();
};
//單擊增加或減少按鈕的方法
functionchangeNumber(event){
varnode=event&&event.target;
varv=0;
if(node.value&&node.value=='+'){
//node.previousElementSibling.value=parseInt(node.previousElementSibling.value)+1;
node.previousElementSibling.value++;
v=node.previousElementSibling.value;
node.previousElementSibling.previousElementSibling.disabled=false;
}else{
//if(node.value&&node.value=='+')
if(node.nextElementSibling.value>1){
node.nextElementSibling.value--;
v=node.nextElementSibling.value;
if(v==1){
node.disabled=true;
}
}
}
//存儲商品數量
varid=node.parentNode.parentNode.id;
for(vargoodofskin_procts){
if(id==good.id){
good.number=v;
}
}
}
//每個商品小計的方法
functionsubtotal(event){
varnode=event&&event.target;
//varid=node.parentNode.parentNode.id;
//for(vargofskin_procts){
//if(g.id==id){
//alert(g.price);
//}
//}
//varprice=;
varprice=node.parentNode.previousElementSibling.innerText;
varnum=node.parentNode.children[1].value;
node.parentNode.nextElementSibling.innerText=(num*price).toFixed(2);
}
//檢驗該商品是否選中
functioncheckedRow(event){
event.target.parentNode.parentNode.firstElementChild.firstElementChild.checked=true;
//event.target.parentNode.parentNode.cells[0].firstElementChild.checked=true;
//vartbody=event.target.parentNode.parentNode.parentNode;
//event.target.parentNode.parentNode.parentNode.rows[3].cells[0].firstElementChild.checked=true;
}
//檢查是否全選
functioncheckedAllRows(){
varchks=document.querySelectorAll('.good-check');
varflag=true;
for(varckofchks){
if(!ck.checked){
flag=false;
break;
}
}
document.querySelector('#chk_alla').checked=flag;
}
//統計商品總量和總價格
functiontotalAcount(){
vartotal=0;
vartotal_price=0;
varchks=document.querySelectorAll('.good-check');
for(varckofchks){
if(ck.checked){
id=ck.parentNode.parentNode.id;
for(vargoodofskin_procts){
if(id==good.id){
total+=~~good.number;
total_price=total_price+(good.number*good.price);
good.ischecked=true;
}
}
}
}
document.querySelector('#good_count').innerText=total;
document.querySelector('#goods_total').innerText=total_price;
}
})();
</script>
</body>
</html>