2017-03-06 43 views
0

jQuery的變化功能不工作,這是我的javascript:在一些瀏覽器的移動

$(document).ready(function(){ 
    $(".txt-qty").on('change',function(){ 
     var product_variant_id = this.id; 
     var qty = $(this).prop('value'); 
     if(!isNaN(qty) == true) { 
      jQuery.ajax({ 
       type: "POST", 
       url: "<?=base_url("https://stackoverflow.com/q/qty_data")?>", 
       dataType: 'JSON', 
       async: false, 
       data: { 
        qty: qty, 
        product_id: product_variant_id, 
        payment_method_id : payment_method_id 
       }, 
       success: function (res) { 
        if(res['message'] == 'reload'){ 
         location.reload(); 
        } 

        var product_variant_id = (res)["id"]; 
        var price = (res)["price"]; 
        var subtotal = (res)['subtotal']; 
        var total_price = (res)['total_price']; 
        $('#subtotal').html(subtotal); 
        $('#total_price').html(total_price); 
        $('#point_reward').html(res['point']); 
        if (product_variant_id == null) { 
         $(".cart-data-total").html(price); 
        } else { 
         $("#product_price_total_" + product_variant_id).html(price); 
        } 
       } 
      }); 
      return false; 
     }else{ 
      alert('Silahkan masukan angka quantity dengan benar'); 
     } 
    }); 
}); 

這是我的HTML表單:

<div class="cart-data-qty pull-left col-md-1 col-xs-4"> 
    <input value="<?=$qty?>" class="form-control txt-qty" data-product-price="<?=$variant_discount_price?>" data-promo-id="<?=$product['promo_id']?>" data-product-variant-id="product_variant" id="<?=$row['product_id']?>" maxlength="2" type="text"> 
</div> 

的情況下,上述工作的代碼找到mozila和谷歌Chrome在PC類型,但它不能在移動設備上的某些瀏覽器中工作,例如:原始的三星互聯網瀏覽器UCbrowser,但它可以在android chrome中工作。

爲什麼它不起作用?可有人告訴我這一點,我應該怎麼做才能解決這個問題 謝謝(:

+0

您可以嘗試定位不同的事件,例如'keyup',因爲您正在使用''元素 –

回答

0

你可以嘗試:.on('keyup change'甚至.on('keyup change drop paste',而不是隻.on('change' :)

這應該工作。

祝你好運!