美好的一天。攔截點擊,做出一些行動,然後再傳播「點擊」
今天,它已被要求我開發一個JavaScript(jQuery)跟蹤成千上萬的網頁上的一些事件。
我必須攔截一些可點擊元素的點擊,進行一些調用,然後讓頁面一如既往地繼續工作。 例如,假設頁面上有一些文本輸入,一些複選框,一些鏈接和一個提交按鈕。
讓我們暫時忽略提交按鈕。我會稍後處理它。我有這樣的想法:
$(document).ready(function() {
$('input[type=button], input[type=submit], input[type=checkbox], button, a').bind('click', function(evt, check) {
//evt.preventDefault();
console.log("id:"+ evt.target.id+", class:"+evt.target.class+", name:"+evt.target.name);
console.log (check);
evt.target.trigger('click', 'check');
});
});
我不得不使用jquery 1.5,不能更新到沒有更多。
我猜測,這可能是staight前鋒,但上面返回代碼此錯誤:
id:terms, class:undefined, name:terms
undefined //this is ok, the check variable will be used to distinguish real clicks from triggered ones.
Uncaught TypeError:
Object #<HTMLInputElement> has no method 'trigger'
(anonymous function)
E jquery-1.5.min.js
d.event.handle jquery-1.5.min.js
j.handle.l jquery-1.5.min.js
我會忘了什麼......?提前致謝。
非常感謝,我測試並儘快接受答案。謝謝。 –