jQuery的点击()链接 [英] jquery click() on a link

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

问题描述

通过ajax调用加载页面时,我试图触发对链接的点击,我尝试了发现的所有方法,但我无法做到这一点.

I'm trying to trigger a click on a link when a page loads via ajax call, I tried all methods I found, but I can't manage to do that.

考虑到我要在其上触发点击的链接是由该代码给出的

Considering that the link on which I want to trigger the click is given by this code

<a href="download.php?file=cloud/index.html" target="_blank" id="cliccami">Click here</a>

这是我尝试过的代码

<script> $("#cliccami").trigger("click"); </script>
<script> $("#cliccami")[0].click(); </script>
<script> window.open($("#cliccami").attr("href"), "_blank"); </script>

脚本和元素都在通过ajax调用加载的页面中. 谁能帮助我找出问题所在?

Both script and element are in the page loaded via ajax call. Could anyone help me to find out what's the matter?

推荐答案

编辑,我认为这是您要查找的内容:

EDIT, I think this is what you're looking for:

html:

<a href="http://www.google.com" target="_blank" id="cliccami">Click here</a>

jQuery:

$(document).ready(function() {

    $('#cliccami').click(function(e) {
        window.open($(this).attr('href'));
        e.preventDefault();
    });

    $('#cliccami').click();
});

在我的示例中(JSFiddle: http://jsfiddle.net/qw9BW/)#cliccami'捕获单击事件,将其发出警报,然后停止.然后在页面加载时运行$ .click()以强制发生click事件.

In my example (JSFiddle: http://jsfiddle.net/qw9BW/) #cliccami's click event is captured, alerted, then stopped. then a $.click() is ran on page load to force the click event to happen.

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

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