javascript Jquery -- 任何事件都会触发动作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5123356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 16:02:23  来源:igfitidea点击:

Jquery -- Action fires on any event

javascriptjquery

提问by Peter Olson

Is there something in jquery where a function is triggered when any event is fired?

jquery 中是否存在在触发任何事件时触发函数的内容?

I'd like something like this:

我想要这样的东西:

$("*").anyEvent(function(){
  $("#error").html("");
});

回答by Matt Ball

$('*').on('blur change click dblclick error focus focusin focusout hover keydown keypress keyup load mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup resize scroll select submit', function(){
  $('#error').empty();
});

...but would you want to do this?

……但是你想这样做吗?