Drupal在调用输入文本更改事件时进入循环

Drupal gets into loop when calling input text change event

本文关键字:事件 循环 调用 输入 文本 Drupal      更新时间:2023-09-26

我正在使用Drupal 7,问题是我有一个输入类型文本,默认情况下span中有2个箭头(添加购物车按钮的小部件数量)。

当使用js_injector模块获取输入的'change()'事件时,奇怪的事情发生了,一个循环开始改变输入的值,或多或少取决于点击的箭头。

    jQuery(function($) {
        $(document).ready(function(){
              $('#edit-quantity').bind('change keydown keyup click input submit mouseenter', function (e) {alert('Type: ' + e.type); });
        });
      });

->这工作正常,但没有得到箭头跨度点击选项:

     $('#edit-quantity').bind('keydown keyup click input submit mouseenter',...

->这些选项创建一个循环:

     $('#edit-quantity').bind('change ...',

     $('#edit-quantity').change(function (e) {alert('Type: ' + e.type); });

我的观点是,为什么这个。change()事件创建这样一个循环?或者我如何停止它来使用事件?

谢谢你,

你可以用"input"代替change

$('#textbox').on('input', function() {
    // do your stuff
});

最好不要对文本字段使用更改。更改更倾向于单选按钮,选择字段,复选框等…

希望它能帮助到一些人,最后我只是寻找了所有改变的可能性。不仅在输入中,也在用span表示的"按钮"中。我做了一些小技巧,结果是这样的:

    jQuery(function($) {
    function value()
    {
       if($(this).index()!=0) //Just execute once
       {
               var price=parseFloat(document.getElementsByClassName('field-item')[0].innerHTML.replace(' €','')).toFixed(2);
               var quantity = parseFloat($("#edit-quantity").val());
               price *= quantity;
               var glbvar = price.toFixed(2).replace('.',',')+' €';
       //Set Price
               document.getElementsByClassName('field-name-commerce-price')[0].getElementsByClassName('field-item')[0].innerHTML = glbvar ;
       }
    }
      $(document).ready(function(){
       //When refreshing the value get lost:
            if( parseFloat($("#edit-quantity").val()) != 1)  value();

    /*For input*/ $("#edit-quantity").bind("propertychange keyup paste input",value);
    /*For span*/  $('span').bind('click',value);
       });
     });