本文介绍了模拟链接点击而不与jquery中的用户互动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要模拟对href元素的点击,但不重定向浏览器上的页面.实际上是在用户不知情的情况下.我该如何实现?
Wanna simulate a click on href element, but without redirect the page on browser. Actually without the user's knowledge. How can I achieve this?
示例:
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
按钮
Your remote click needs to be triggered somehow. In this example its being done by the click-this
button
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/
jsFiddle: https://jsfiddle.net/0oecovtj/1/
这篇关于模拟链接点击而不与jquery中的用户互动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!