如何模拟锚链接单击 [英] How to simulate anchor link click

查看:65
本文介绍了如何模拟锚链接单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试触发.jquery的链接点击。有人知道以下原因为何无效。

I'm trying to trigger a link click for .jquery. Does someone know why the following doesn't work.

<!DOCTYPE  HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html lang="en"> 
  <head> 
    <title>test</title>
  </head>
  <body> 
    <div>
       <a id="google_link" href="http://google.com" target="_blank">click to go to google</a>
    </div>
    <div id="google_link_proxy">click here to do the same as the link above</div>

    <script type="text/javascript">      
     $("#google_link_proxy").click(function(event){
         $("#google_link").click();
     });
    </script>
  </body>
</html>


推荐答案

看起来像您的 $( google_link_proxy)选择器已关闭。尝试 $(#google_link_proxy)

Looks like your $("google_link_proxy") selector is off. Try $("#google_link_proxy").

您还需要使用<$ c $关闭观察调用c>})。

这些是上面代码的语法错误,尽管我认为默认情况下jQuery不提供这些功能。

Those are the syntax errors with the code above though I don't think those functions are provided in jQuery by default.

这是我想找的:

$("#google_link_proxy").click(function(event){
    window.open($("#google_link").attr('href'),'_blank')
});

这篇关于如何模拟锚链接单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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