How can I bind many event handlers to one event using jQuery?

ε祈祈猫儿з 提交于 2019-12-04 20:18:25

That does work. I just double checked with this code:

$(document).ready(function() {
  $("#FirstName").focus(function() {
    console.log("focus1");
  });

  $("#FirstName").focus(function() {
    console.log("focus2");
  });
});

And it does produce two console messages when the input field is focused.

Are you positive that both your handlers aren't running?

Can't you create on "master" function that calls all needed handlers?

$(this).focus( function() { function1();function2();etc..... });

Pim Jager

This should theoretically work, try if all handlers are fired using:

$(this).focus( function() { alert('handler1'); });
$(this).focus( function() { alert('handler2'); });
$(this).focus();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!