jquery購物車即時結算特效實現思路

來源:互聯網
上載者:User

複製代碼 代碼如下:
$(function(){
$(".child_tab tr:last-child").find("td").css({borderBottom:'none'})
//獲得文字框對象
var t = $(".amount-input");
//數量增加操作
$(".amount-up").click(function(e){
var c1=parseInt($(this).prev().val());
$(this).prev().val(c1+1);
e.preventDefault()
setTotal();
});
//數量減少操作
$(".amount-down").click(function(e){
var c1=parseInt($(this).next().val());
if(c1>=1){
$(this).next().val(c1-1);
};
e.preventDefault()
setTotal();
});
function setTotal(){
//取每個條件的值
var num1=$(".sum1").text();
var num2=$(".sum2").text();
var num3=$(".sum3").text();
var total=0;
var x1=4,x2=10,x3=49;
//遍曆合計件數
t.each(function(index,ele){
total+=parseInt($(ele).val());
});
$(".figure").html(total);
//判斷個數滿足哪個要求
if(total<x2){
b2=num1
}else if(total>=x2&&total<=x3){
b2=num2
}else if(total>=x3){
b2=num3
}
$(".money").html((total*b2).toFixed(2)+'元');//toFixed()是保留小數點的函數很實用哦
}
//初始化
setTotal();

})

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.