jQuery 单击控制另一次单击
我想将点击操作从 a#click1
传递到 a#click2
。如果我点击 a#click1
,则应打开链接 http://www.google.com
。怎么做呢?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
$('a#click1').click(function() {
$('a#click2').click();
});
});
</script>
<div id="wrap1">
<div id="content1">
<a id="click1" href="">click</a>
</div>
</div>
<div id="wrap2">
<div id="content2">
<a id="click2" href="http://www.google.com">click</a>
</div>
</div>
I want to pass the click action from a#click1
to a#click2
. If I click a#click1
, then the link http://www.google.com
should be opened. How to do that?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
$('a#click1').click(function() {
$('a#click2').click();
});
});
</script>
<div id="wrap1">
<div id="content1">
<a id="click1" href="">click</a>
</div>
</div>
<div id="wrap2">
<div id="content2">
<a id="click2" href="http://www.google.com">click</a>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不明白为什么你所做的不起作用,但如果你想做的只是导航到第二个锚点
href
,你可以这样做:I can't see why what you have done wouldn't work but if all you want to do is navigate to the 2nd anchors
href
, you could do:我相信只有当您像为第一个链接那样声明第二个链接的点击功能时,这才有可能。
所以这实际上应该有效:
它也应该可以开箱即用!
I belive this is only possible if you declare a click function for the second link like you did for the first.
So this should actually work:
It should also work for s right out of the box!
这对我有用
this works for me