开发者

jQuery + Greasemonkey, Click event doesn't trigger on correct element?

$(Constants.Selectors.Submit_Button).bind('click', function () {
    GM_log('Event run: id = ' + this.id + ' self = ' + this);
});

The above code appears to run when the click event is triggered by the document (or otherwise some other all-page encompassing element or set of elements.) The console ou开发者_运维百科tput is this: Script: Event run: id = undefined self = [object XPCNativeWrapper [object HTMLDocument]]

The selector is a simple string "#buttonID" where buttonID is significantly obfuscated (I'm sure there are no name conflicts) and is part of an HTML form I have injected into the page. (Namely an input element with the attribute "type" set to "button").

Does anyone know why this might be? I'm clueless on this one.


What kind of version of jQuery you are using? It's been a while since i played in GM, but i found code of mine and it was done with 1.3.2 and it's still working for me as long as click function is under document ready function.

var $jq = jQuery.noConflict();

$jq(function(){
  $jq('#buttonID').click(function(){
   runCode;
  });
 });


instead of doing something like this:

var elmLink = document.getElementById('somelink');
elmLink.onclick = 'my_func(this)';

do something like this:

var elmLink = document.getElementById('somelink');
elmLink.addEventListener("click", my_func, true);

from here

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜