1

我目前在作品中有一个数量输入,可以让用户输入一个数字,但如果输入旁边有一个选项可以让他们单击“+”号添加到数量上,我也会喜欢它。我该怎么做呢?

喜欢这个网站数量选项: http: //www.nastygal.com/clothes-tops-graphics/going-batty-muscle-tee

我的数量输入代码:

QTY:</b> {{ product | product_quantity_input }}
4

1 回答 1

0
//initialize the input to 1
$(".quantity").val("1");

//when clicking the plus button, add one
$(".plus-btn").click(function(){
    //get the current value and convert it to an integer
    var currVal = parseInt($(".quantity").val(), 10);
    //set the incremented value 
    $(".quantity").val(currVal+1);
});

//when clicking the minus button, subtract one
$(".minus-btn").click(function(){
    //get the current value and convert it to an integer
    var currVal = parseInt($(".quantity").val(), 10);
    //set the decremented value if its not less than 1
    if(currVal > 1){
        $(".quantity").val(currVal-1);
    }
});

参见示例:http: //jsfiddle.net/ES89t/

于 2013-10-01T03:17:40.363 回答