jquery点击对超链接不起作用 [英] jquery click doesn't work on hyperlink

查看:31
本文介绍了jquery点击对超链接不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的链接点击模拟,我想用 jQuery 做它.从我读到的,这应该有效,但下面的代码不起作用.如果我作为其他事件的一部分或某事的一部分做同样的事情,则不会发生任何事情.想法?

I have a simple link click simulation that I want to do using jQuery. From what I read, this should work, but the code below doesn't work. Nothing happens if I do the same thing as a part of some other event or something either. Thoughts?

<script type="text/javascript">
  $(function() {
    $("#lnk_0").click();
  });
</script>

<a id="lnk_0" href="http://mydomain.com/mypage.html">link</a>

推荐答案

参见 click():

触发每个的点击事件匹配元素.

Triggers the click event of each matched element.

导致所有具有被绑定到那个点击事件是执行.

Causes all of the functions that have been bound to that click event to be executed.

需要注意的重要一点是它不会重复点击链接.它只触发相关事件.如果您想更改位置:

The important thing to note is that it does not duplicate clicking the link. It only triggers associated events. If you want to change location:

var link = $("#link_0");
link.click();
window.location.href = link.attr("href");

但即便如此,这也只是一个近似值,因为它不适合停止事件传播的处理程序.

but even that is only an approximation as it doesn't cater for handlers stopping event propagation.

这篇关于jquery点击对超链接不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆