模式弹出时,(+/-)按钮不起作用

时间:2017-09-19 00:14:36

标签: javascript jquery twitter-bootstrap bootstrap-modal

我想制作一个模态弹出窗口,其中包含一个(+/-)按钮,如果它不在模态内部,它可以工作,但它在模态内部不起作用。

这是我的(+/-)代码:

<div class="col-md-12">

    <button style="border: 1px solid #000000;padding: 2px;color: black" 
    class="incr-btn" data-action="decrease" href="#">-</button>

    <input id="number" type="text" name="quantity" value="1" 
    style="max-height: 29px;max-width: 15px; border: 1px solid #000000">

    <button style="border: 1px solid #000000;padding: 2px;color: black" 
    class="incr-btn" data-action="increase" href="#">+</button>
</div>

这是我的(+/-)js:

<script type="text/javascript">


$(".incr-btn").on("click", function (e) {
    var $button = $(this);


var oldValue = $button.parent().find('.quantity').val();
    $button.parent().find('.incr-btn[data-action="decrease"]').removeClass('inactive');
        if ($button.data('action') == "increase") {
            var newVal = parseFloat(oldValue) + 1;
        } else {
            // Don't allow decrementing below 1
            if (oldValue > 1) {
                var newVal = parseFloat(oldValue) - 1;
            } else {
                newVal = 1;
                $button.addClass('inactive');
            }
        }
        $button.parent().find('.quantity').val(newVal);
        e.preventDefault();
    });
</script>

0 个答案:

没有答案
相关问题