購物車中數量增加與減少 根據數量改變總體價格 限制輸入框輸入其他非數字

$(".increment").click(function () {
    var t   =   $(this).parent().find('input[class*=itxt]');
    t.val(parseInt(t.val())+1);
    getTotalPrice();
})
$(".decrement").click(function () {
    var t   =   $(this).parent().find('input[class*=itxt]');
    t.val(parseInt(t.val())-1);
    if(parseInt(t.val())<=0){
        t.val(1);
    }
    getTotalPrice();
})
$(".itxt").blur(function () {
    var t   =   $(this).val();
    if(t<1){
        alert('商品數量不能小於0');
    }
    getTotalPrice();

})


function getTotalPrice() {
    $("#tab tr").each(function () {
        var s   =   parseInt($(this).find('input[class*=itxt]').val())*parseFloat($(this).find('span[class*=one_price]').text());
        $(this).find('span[class*=total_price]').html(s);
    })
}
限制輸入非數字的字符
οninput="this.value=this.value.replace(/\D/g,'')"

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章