开发者

Is it possible to chain multiple events with one function in jQuery [duplicate]

开发者 https://www.devze.com 2023-02-17 03:56 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Jquery event chaining Traditionally we may write:
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Jquery event chaining

Traditionally we may write:

    $("selector").click(function () {

    });

but is it possible to chain events, something like so:

    $("selector").click,keyu开发者_StackOverflow中文版p,keydown(function () {

    });

I'm aware of the fact that I could write a function and reference that function in three seperate handlers, but this would be cleaner.


Use .bind()

$("selector").bind("keyup keydown click", function () {

});

For jQuery 1.7 and later, using the new API .on() is more preferred

$("selector").on("keyup keydown click", function () {

});
0

精彩评论

暂无评论...
验证码 换一张
取 消