2016-11-05 128 views
1

我添加到我的product-list.tpl輸入與+/-按鈕的作品,直到我使用任何過濾器從塊層模塊,然後+/-按鈕停止工作。PrestaShop自定義輸入塊的問題

我的輸入是這樣的:

<input type='button' value='-' class='qtymin' field='qty' /> 
<input type="text" class='qtynum' name="qty" id="quantity_to_cart_{$product.id_product|intval}" value="1"/> 
<input type='button' value='+' class='qtypl' field='qty' /> 

JS代碼是:

jQuery(document).ready(function(){ 
     // This button will increment the value 
     $('.qtyplus').click(function(e){ 
      // Stop acting like a button 
      e.preventDefault(); 
      // Get the field name 
      fieldName = $(this).attr('field'); 
      // Get its current value 
      var currentVal = parseInt($('input[name='+fieldName+']').val()); 
      // If is not undefined 
      if (!isNaN(currentVal)) { 
       // Increment 
       $('input[name='+fieldName+']').val(currentVal + 1); 
      } else { 
       // Otherwise put a 0 there 
       $('input[name='+fieldName+']').val(0); 
      } 
     }); 
     // This button will decrement the value till 0 
     $(".qtyminus").click(function(e) { 
      // Stop acting like a button 
      e.preventDefault(); 
      // Get the field name 
      fieldName = $(this).attr('field'); 
      // Get its current value 
      var currentVal = parseInt($('input[name='+fieldName+']').val()); 
      // If it isn't undefined or its greater than 0 
      if (!isNaN(currentVal) && currentVal > 0) { 
       // Decrement one 
       $('input[name='+fieldName+']').val(currentVal - 1); 
      } else { 
       // Otherwise put a 0 there 
       $('input[name='+fieldName+']').val(0); 
      } 
     }); 
    }); 

Blocklayered V2.2.0的Prestashop v1.6.1.8

任何想法,爲什麼這不工作?

+0

你有沒有試着用$( 'parent_class')上( '點擊', 'qtyminus',功能.... –

+0

很抱歉,但我。不知道該怎麼做,我有編程的基本知識。Colud你給我一個樣本或寫更多關於它的東西? –

回答

1

嘗試將事件附加文檔:

jQuery(document).ready(function(){ 
     // This button will increment the value 
     $(document).on('click', '.qtyplus', function(e){ 
      // Stop acting like a button 
      e.preventDefault(); 
      // Get the field name 
      fieldName = $(this).attr('field'); 
      // Get its current value 
      var currentVal = parseInt($('input[name='+fieldName+']').val()); 
      // If is not undefined 
      if (!isNaN(currentVal)) { 
       // Increment 
       $('input[name='+fieldName+']').val(currentVal + 1); 
      } else { 
       // Otherwise put a 0 there 
       $('input[name='+fieldName+']').val(0); 
      } 
     }); 
     // This button will decrement the value till 0 
     $(document).on('click', '.qtyminus', function(e) { 
      // Stop acting like a button 
      e.preventDefault(); 
      // Get the field name 
      fieldName = $(this).attr('field'); 
      // Get its current value 
      var currentVal = parseInt($('input[name='+fieldName+']').val()); 
      // If it isn't undefined or its greater than 0 
      if (!isNaN(currentVal) && currentVal > 0) { 
       // Decrement one 
       $('input[name='+fieldName+']').val(currentVal - 1); 
      } else { 
       // Otherwise put a 0 there 
       $('input[name='+fieldName+']').val(0); 
      } 
     }); 
    }); 
+0

謝謝,這是簡單的:)我現在看到它,但沒有你的幫助,我可能沒有解決它由我自己。 –

+0

你不客氣;) – sarcom