gpt4 book ai didi

javascript - 模拟链接单击而不与 jquery 中的用户交互?

转载 作者:行者123 更新时间:2023-11-30 12:18:42 25 4
gpt4 key购买 nike

想要模拟点击 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/

关于javascript - 模拟链接单击而不与 jquery 中的用户交互?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31687759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com