Javascript Greasemonkey脚本未单击该按钮
这里的问题是什么;它不点击 我的代码:Javascript Greasemonkey脚本未单击该按钮,javascript,jquery,button,click,greasemonkey,Javascript,Jquery,Button,Click,Greasemonkey,这里的问题是什么;它不点击 我的代码: // ==UserScript== // @name premiumleech // @namespace premiumleech // @include http://generator.premiumleech.com/link/*.html // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js // @grant GM
// ==UserScript==
// @name premiumleech
// @namespace premiumleech
// @include http://generator.premiumleech.com/link/*.html
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
/*
<p class="leech-btn"><button onclick="javascript:window.open('http://generator.premiumleech.com/redir/BtPpnGJv2HcZRa2BTxsEQzUdDQbb6WO1','_blank');">Leech it!</button></p>
*/
/*
/html/body/div[2]/div/section/p[2]
*/
var targBtn = $("#content > p.leech-btn > button");
if (targBtn.length) {
targBtn[0].click ();
}
jQuery的click()方法不会对元素触发click操作。它会触发为click事件处理程序注册的操作,如果传递了参数,它将用作click元素的回调函数。用于单击您需要使用的HTML元素
$("body > div:second > div:first > div:first > p:second").get(0).click();
这将本质上选择HTML元素(而不是jQuery对象)并触发click事件
.click()
应该可以正常工作。您是否从该$(“body>div:second>div:first>div:first>p:second”)获取元素?不起作用我测试的链接是这样的
$("body > div:second > div:first > div:first > p:second").get(0).click();