0
我在写扩展名为chrome,我需要自动点击下一页的链接。
我用jQuery.noConflict();
在我的Chrome控制台总是抛出的错误 - jquery-3.1.0.min.js:2 Uncaught TypeError: target.dispatchEvent is not a function.
这是我的代码:模拟鼠标点击链接进行Chrome扩展
var dispatchMouseEvent = function (target, var_args) {
var e = document.createEvent("MouseEvents");
e.initEvent.apply(e, Array.prototype.slice.call(arguments, 1));
target.dispatchEvent(e);};
function GoToNextPage() {
var link_nextpage = null;
jQuery(function ($) {
var pages = $('#results-pagination');
var next_page = pages.find('.next');
var link_nextpage = null;
if (next_page.length) {
link_nextpage = next_page.find('a');
dispatchMouseEvent(link_nextpage, 'click', true, true);
}
});
}
能否请你解释一下,如果有可能做到这一点,或者告诉我做错了什么?
link_nextpage是一个jQuery对象,而不是一个DOM元素。请使用.trigger或link_nextpage [0],更重要的是:调试您的代码! – wOxxOm
link_nextpage [0]的作品,感谢您的帮助。 –