觸發方法調用的事件我想在JavaScript中檢測觸發點擊事件,我的代碼是如何檢測jQuery的
$(".my_button").click(function(){
// if event fired form .trigger() method from other method or event then do something
// actuall code for click event is here
})
.....
.....
$('.other_first_button').click(function(){
// code of other first button
$(".my_button").trigger('click');
});
.....
.....
$('.other_second_button').click(function(){
// code of other second button
$(".my_button").trigger('click');
});
注:我想使用jQuery trigger()
方法標識$(".my_button").click()
點擊事件呼叫。
提前感謝您的時間。
你可以通過額外的數據到事件處理程序,請參見[商務部](http://api.jquery.com/trigger/) –
我抓到你了,感謝@ A.Wolff –
需要注意的是,你可以檢查'event.isTrigger',但這不是公共支持:https://github.com/jquery/api.jquery.com/issues/319(編輯:順便說一句主要開發者建議檢查'event.originalEvent',但恕我直言更好的辦法是在處理它時,使用'$ .fn.trigger()'方法將參數傳遞給事件處理函數)https://jsfiddle.net/vk1e3sp0/1 –