Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击数字微调器-php后更新数据库_Javascript_Php_Jquery_Twitter Bootstrap - Fatal编程技术网

Javascript 单击数字微调器-php后更新数据库

Javascript 单击数字微调器-php后更新数据库,javascript,php,jquery,twitter-bootstrap,Javascript,Php,Jquery,Twitter Bootstrap,我有数字微调器,从引导输入文本和按钮。代码如下: <div class="input-group"> <span class="input-group-btn"> <button type="button" class="btn btn-default btn-number btn-sm" id="<?=$idBarang?>" disabled="disabled" data-type="minus" data-field

我有数字微调器,从引导输入文本和按钮。代码如下:

<div class="input-group">
     <span class="input-group-btn">
          <button type="button" class="btn btn-default btn-number btn-sm" id="<?=$idBarang?>" disabled="disabled" data-type="minus" data-field="quant[<?=$i++?>]">
               <span class="glyphicon glyphicon-minus"></span>
          </button>
     </span>

     <input type="text" name="quant[<?=$j++?>]" class="form-control input-number input-sm" style="text-align:center;"  value="<?=$jumlah?>" min="1" max="10">

     <span class="input-group-btn">
          <button type="button" class="btn btn-default btn-number btn-sm" id="<?=$idBarang?>" data-type="plus" data-field="quant[<?=$k++?>]">
     <span class="glyphicon glyphicon-plus"></span>
          </button>
     </span>
</div>


这是给你的第一个问题,我没有尝试过,但我认为它会起作用

var urlTroli = "edit_troli.php";
var reloadPageNow;
    $('.btn-number').click(function(e){
    e.preventDefault();

    if(reloadPageNow)
         clearTimeout(reloadPageNow );


    id_pro = this.id;
    fieldName = $(this).attr('data-field');
    type      = $(this).attr('data-type');
    var input = $("input[name='"+fieldName+"']");
    var currentVal = parseInt(input.val());
    if (!isNaN(currentVal)) {
        if(type == 'minus') {
            newVal = currentVal -1;
            if(currentVal > input.attr('min')) {
                input.val(newVal).change();
            } 
            if(parseInt(input.val()) == input.attr('min')) {
                $(this).attr('disabled', true);
            }

        } else if(type == 'plus') {
            newVal = currentVal +1;
            if(currentVal < input.attr('max')) {
                input.val(newVal).change();
                $.post(urlTroli, {idPro: id_pro, jml:newVal} ,function() {
                 reloadPageNow = setTimeout(function()
                 {
                     window.location.replace("edit_troli.php"); 
                 },500);
                });
            }
            if(parseInt(input.val()) == input.attr('max')) {
                $(this).attr('disabled', true);
            }
        }
    } else {
        input.val(0);
    }

});
$('.input-number').focusin(function(){
   $(this).data('oldValue', $(this).val());
});
$('.input-number').change(function() {

    minValue =  parseInt($(this).attr('min'));
    maxValue =  parseInt($(this).attr('max'));
    valueCurrent = parseInt($(this).val());

    name = $(this).attr('name');
    if(valueCurrent >= minValue) {
        $(".btn-number[data-type='minus'][data-field='"+name+"']").removeAttr('disabled')
    } else {
        alert('Sorry, the minimum value was reached');
        $(this).val($(this).data('oldValue'));
    }
    if(valueCurrent <= maxValue) {
        $(".btn-number[data-type='plus'][data-field='"+name+"']").removeAttr('disabled')
    } else {
        alert('Sorry, the maximum value was reached');
        $(this).val($(this).data('oldValue'));
    }


});
$(".input-number").keydown(function (e) {
        // Allow: backspace, delete, tab, escape, enter and .
        if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 ||
             // Allow: Ctrl+A
            (e.keyCode == 65 && e.ctrlKey === true) || 
             // Allow: home, end, left, right
            (e.keyCode >= 35 && e.keyCode <= 39)) {
                 // let it happen, don't do anything
                 return;
        }
        // Ensure that it is a number and stop the keypress
        if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
            e.preventDefault();
        }
    });
var urlTroli=“edit_troli.php”;
var重新加载页面现在;
$('.btn编号')。单击(函数(e){
e、 预防默认值();
如果(重新加载页面现在)
clearTimeout(重新加载PageNow);
id_pro=this.id;
fieldName=$(this.attr('data-field');
type=$(this.attr('data-type');
变量输入=$(“输入[name=”+fieldName+“]”);
var currentVal=parseInt(input.val());
如果(!isNaN(currentVal)){
如果(类型=='减'){
newVal=currentVal-1;
如果(currentVal>input.attr('min')){
input.val(newVal.change();
} 
if(parseInt(input.val())==input.attr('min')){
$(this.attr('disabled',true);
}
}else if(类型=='plus'){
newVal=currentVal+1;
if(currentVal=最小值){
$(“.btn编号[数据类型=”减去“][数据字段=”“+name+”]”)。removeAttr('已禁用')
}否则{
警报(“对不起,已达到最小值”);
$(this.val($(this.data('oldValue'));
}
if(valueCurrent=35&&e.keyCode
var urlTroli = "edit_troli.php";
var reloadPageNow;
    $('.btn-number').click(function(e){
    e.preventDefault();

    if(reloadPageNow)
         clearTimeout(reloadPageNow );


    id_pro = this.id;
    fieldName = $(this).attr('data-field');
    type      = $(this).attr('data-type');
    var input = $("input[name='"+fieldName+"']");
    var currentVal = parseInt(input.val());
    if (!isNaN(currentVal)) {
        if(type == 'minus') {
            newVal = currentVal -1;
            if(currentVal > input.attr('min')) {
                input.val(newVal).change();
            } 
            if(parseInt(input.val()) == input.attr('min')) {
                $(this).attr('disabled', true);
            }

        } else if(type == 'plus') {
            newVal = currentVal +1;
            if(currentVal < input.attr('max')) {
                input.val(newVal).change();
                $.post(urlTroli, {idPro: id_pro, jml:newVal} ,function() {
                 reloadPageNow = setTimeout(function()
                 {
                     window.location.replace("edit_troli.php"); 
                 },500);
                });
            }
            if(parseInt(input.val()) == input.attr('max')) {
                $(this).attr('disabled', true);
            }
        }
    } else {
        input.val(0);
    }

});
$('.input-number').focusin(function(){
   $(this).data('oldValue', $(this).val());
});
$('.input-number').change(function() {

    minValue =  parseInt($(this).attr('min'));
    maxValue =  parseInt($(this).attr('max'));
    valueCurrent = parseInt($(this).val());

    name = $(this).attr('name');
    if(valueCurrent >= minValue) {
        $(".btn-number[data-type='minus'][data-field='"+name+"']").removeAttr('disabled')
    } else {
        alert('Sorry, the minimum value was reached');
        $(this).val($(this).data('oldValue'));
    }
    if(valueCurrent <= maxValue) {
        $(".btn-number[data-type='plus'][data-field='"+name+"']").removeAttr('disabled')
    } else {
        alert('Sorry, the maximum value was reached');
        $(this).val($(this).data('oldValue'));
    }


});
$(".input-number").keydown(function (e) {
        // Allow: backspace, delete, tab, escape, enter and .
        if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 ||
             // Allow: Ctrl+A
            (e.keyCode == 65 && e.ctrlKey === true) || 
             // Allow: home, end, left, right
            (e.keyCode >= 35 && e.keyCode <= 39)) {
                 // let it happen, don't do anything
                 return;
        }
        // Ensure that it is a number and stop the keypress
        if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
            e.preventDefault();
        }
    });