简体   繁体   English

确定文本框值更改后是否立即单击按钮

[英]Determine if button is clicked right after textbox value change

I have screen like following: 我的屏幕如下所示:

在此处输入图片说明

I have bound the change event of textboxes under box2 column.Now the change event is fired when a user clicks out after changing the values but I do not want the user to click the Buttons in the screen after making the change in box2 textboxes. 我已绑定了change下BOX2文本框的事件column.Now当用户改变值后点击了变化事件触发,但我不希望用户点击使在BOX2文本框的改变后的屏幕的按钮。

This means I want to prevent the click of the buttons if a user is clicking on them right after making a change in any of the textboxes but at the same time the change event of the particular box should fire as usual. 这意味着如果用户在更改任何文本框后立即单击按钮,则我想避免单击按钮,但与此同时,应照常触发特定框的change事件。

Is it possible to find out the last widget or the event fired in an event,It sounds odd but I can stop the click of the button if I can determine that very last thing happened was the change of textbox. 是否有可能找到最后一个窗口小部件或某个事件中触发的事件,这听起来很奇怪,但是如果我可以确定发生的最后一件事是文本框的更改,那么我可以停止单击按钮。

 //Change listener of textboxes
  jQuery('#parent').on('change','.textbox',function(e){

        var btn = jQuery(this).closest('.button');         
        if(btn.length){  
          jQuery(this).addClass('red',500,function(){ 
             var poObj = {'changedRef':{'val':jQuery(this)}};      
             btn.triggerHandler('click',poObj);
          });
        } 
      });

    //this is a buttonClick  
      jQuery('.button').on('click',handlerBtnClick);

You can see from the code that change on the textbox is actually calling the click of the corresponding button that is in its row.But the problem is if a user clicks on a button of different row after making a change in a box. 从代码中可以看到,文本框上的更改实际上是在单击该行中相应按钮的单击,但是问题是用户是否在更改框中后单击另一行的按钮。

Ideas please? 有什么想法吗?

Thanks 谢谢

ps ps

event.type gives the event that was triggered. event.type给出触发的事件。

Have

1)Click function for your button( eg:func1() )

2)Change function for your textboxs( eg:func2() )

Declare a global variable ( for eg: eventTp) 声明一个全局变量(例如:eventTp)

When func2() gets called, assign event.type to the variable eventTp . 调用func2()时,将event.type分配给变量eventTp。 When func1() gets called , check if eventTp variable has the value (Change) . 当func1()被调用时,检查eventTp变量是否具有值(Change)

If yes, then give return false, which will prevent the event from happening. 如果是,则给return false,这将防止事件发生。

Hope this helps. 希望这可以帮助。

You mean something like this ? 你的意思是这样的吗?

 var button = document.getElementById('button'); document.getElementById('box2').addEventListener('change',function(){ button.disabled = true; }); document.getElementById('box1').addEventListener('change',function(){ button.disabled = false; }); 
 <input type='text' id='box1'> <input type='text' id='box2'> <button id='button'>Button</button> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM