如何“触发”使用 Javascript 在特定锚元素上单击事件?最好使用 jQuery
我想要做的是在锚元素上发出一个单击事件(最好使用 jQuery),使浏览器跟随该链接。我知道我的锚选择器是正确的,因为它们从 .length 返回 1。
这是我尝试过的:
$('#awesomeLink').click();
但它不会点击链接。
我怎么做错了?
谢谢!!
What I want to do is issue a click event, preferably with jQuery, on an anchor element, causing the browser to follow that link. I know that my anchor selectors are correct, as they are returning 1 from .length.
Here's what I've tried:
$('#awesomeLink').click();
But it won't follow the link.
How am I doing it wrong?
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么不直接解析 url 并将用户发送到该链接位置呢?
Why not just parse the url and send the user to that link location?
尝试
$('#awesomeLink').trigger("click");
Try
$('#awesomeLink').trigger("click");
不要尝试直接单击链接,只需告诉浏览器加载不同的页面:
这个问题类似于 如何自动点击a-link-with-javascript。
Instead of trying to click the link directly, just tell the browser to load a different page:
This question is similar to how-do-i-automatically-click-a-link-with-javascript.
如果您只是想更改浏览器位置,请尝试:
否则,如果您需要更多信息,那么 这个问题 可能会有所帮助(关于本机点击的其他问题也可能有所帮助)。
If you are just wanting to change the browser location try:
Otherwise if you are needing a bit more, then this question might help (as might the other questions about native clicking).