开发者

jQuery - Find out what triggered the event [duplicate]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜