数量盒加减去不工作

时间:2017-05-21 10:44:24

标签: javascript

大家好我正在处理这个数量的盒子由于某种原因,当按下加号或减号时它没有工作,它应该改变盒子里的数量。

代码

<div class="serial-section-sn J_serialSection">
    <h3 class="label-title">Quantity <i class="icon icon-help"></i></h3>
    <fieldset class="form-section">
        <label class="input-label hide" for="num">Quantity</label>
        <div class="amount-controller" data-module="amount-controller">
            <span id="qtyminus" field="quantity" class="handle"><i class="iconfont"></i></span>
            <input class="input-num" type="text" id="num" name="number" value="{$info.goods_number}">
            <span id="qtyplus" field="quantity" class="handle"><i class="iconfont"></i></span>
        </div>

的Javascript

< script type = "text/javascript"
language = "JavaScript" > $(document).ready(function() {
    $('.qtyplus').click(function(e) {
        e.preventDefault();
        var container = $(this).parents('.amount-controller');
        fieldName = $(this).attr('field');
        var currentVal = parseInt(container.children(".input-num").val());
        var val2 = currentVal + 1;
        if (!isNaN(val2)) {
            container.children(".input-num").val(val2);
        } else {
            container.children(".input-num").val(0);
        }
    });
    $(".qtyminus").click(function(e) {
        e.preventDefault();
        var container = $(this).parents('.amount-controller');
        fieldName = $(this).attr('field');
        var currentVal = parseInt(container.children(".input-num").val());
        if (!isNaN(currentVal) && currentVal > 1) {
            container.children(".input-num").val(currentVal - 1);
        } else {
            container.children(".input-num").val(1);
        }
    });
}); < /script>

0 个答案:

没有答案