[英]Simulating link click without interaction with user in 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:
<div class="myDiv" style="color: red;">Clicking this should open google even though this doesn't have an href</div>
<a class= "click-this" href="https://www.google.com">click this</a>
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/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.