尝试click()事件时出现Greasemonkey错误

时间:2011-12-13 17:59:17

标签: jquery greasemonkey

我正在尝试单击页面上的按钮,我可以获得对象的长度没有问题但是当我尝试单击该项目时出现此错误:

Error: uncaught exception: [Exception... 
 "Component is not available"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  
 location: "JS frame :: resource://greasemonkey/runScript.js :: <TOP_LEVEL> :: line 3"  data: no]

以下是我正在使用的代码:

(function(){
    $('body').append('<input type="button" id="autobop" value="autobop" />');   
    $('#autobop').click(function(){
            //buJmnfJwRG
            alert($('#buJmnfJwRG').length);
            $('#buJmnfJwRG').click(); // error occurs here
            /*
            setInterval(function() {

            }, 2000);*/
        });
})();

3 个答案:

答案 0 :(得分:0)

$(document).ready(function(){
    $('body').append('<input type="button" id="autobop" value="autobop" />'); 

        $('#autobop').click(function(){
            //buJmnfJwRG
            alert($('#buJmnfJwRG').length);
            $('#buJmnfJwRG').click();
        });                
});

答案 1 :(得分:0)

链接到目标页面。 #buJmnfJwRG来自何处,是在目标页面上还是由您的脚本添加?

除非#buJmnfJwRG点击,否则事件处理程序是由您的脚本创建的,使用jQuery,您无法使用$('#buJmnfJwRG').click();(通常)激活它。

尝试:

$('#autobop').click ( function () {
    //buJmnfJwRG
    alert ( $('#buJmnfJwRG').length );

    var clickEvent = document.createEvent ('MouseEvents');
    clickEvent.initEvent ('click', true, true);
    $('#buJmnfJwRG')[0].dispatchEvent (clickEvent);
} );

答案 2 :(得分:0)

我有一个开发人员看看......

$(document).ready(function(){

$('body').append('<input type="button" id="autobop" value="autobop" />');

$('#autobop').click(function(){

//buJmnfJwRG

alert($('#buJmnfJwRG').length);

$('#buJmnfJwRG').click();

});

});