开发者

jQuery - Find out what triggered the event [duplicate]

开发者 https://www.devze.com 2023-02-08 23:42 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: Getting th开发者_如何学Goe ID of the element that fired an event using jQuery
This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Getting th开发者_如何学Goe ID of the element that fired an event using jQuery

How do we find out what triggered an event?

I want to find out if a search input was triggered using the enter key or by clicking on a button.


I assume your binding to the search input using jQuery handlers as such. So just pass the event type along. For more information, pass the entire event object along:

$("input.Search").click(function(event) {
    doMySearch(this, "click");
}).keyup(function(event) {
    doMySearch(this, "keyup");
}); 

function doMySearch(element, eventtype) {
   ...
}
0

精彩评论

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

关注公众号