在jquery中模拟链接点击而不与用户交互?
想模拟点击href元素,但不在浏览器上重定向页面。 实际上没有用户的知识。 我怎样才能做到这一点?
例:
var books = new Array(); $('p.tree_item_leaf').each(function(){ books.push($(this).find('a').attr('href')); }) // for each book I wanna get the link and 'simulates' a click such that I can get the loaded content returned from the link in a variable
提前致谢!
您的远程点击需要以某种方式触发。 在这个例子中,它是通过click-this
按钮完成的
HTML:
Clicking this should open google even though this doesn't have an href click this
JS:
$(".myDiv").on("click mousedown mouseup focus blur keydown change", function(e) { $link = $(".click-this"); console.log($link); $(".click-this")[0].click(); });
jsFiddle: https ://jsfiddle.net/0oecovtj/1/