jquery点击不工作的超链接 [英] jquery click doesn't work on hyperlink
问题描述
我有一个简单的链接点击模拟,我想使用jQuery。从我读到的,这应该工作,但下面的代码不工作。没有什么发生,如果我做同样的事情作为一些其他事件或东西的一部分。
< script type =text / javascript
$(function(){
$(#lnk_0)。click();
});
< / script>
< a id =lnk_0href =http://mydomain.com/mypage.html> link< / a>
请参阅 click()
:
< blockquote>
触发每个
匹配元素的点击事件。
导致所有具有
的函数被绑定
重要的是要注意的是它不会
em>重复单击链接。它只触发关联的事件。如果您要更改位置: var link = $(#link_0);
link.click();
window.location.href = link.attr(href);
但是这只是一个近似值,因为它不能处理停止事件传播的处理程序。 p>
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>
See 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屋!