jQuery的click()没有点击? [英] jQuery's click() is not clicking?

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

问题描述

我认为jQuery的 click()可以让我们添加一个处理程序或只是点击一个元素吗?

I thought jQuery's click() can let us add a handler or just click on an element?

但是,我试过了:

$(function() {
    setTimeout(function() {
        $('a').first().trigger('click'); // or click(), the same
    }, 3000);
});

并等待3秒钟,它不会点击第一个<页面中有一个> 元素...怎么来的?

and waited 3 seconds and it won't click on the first <a> element in the page... how come?

更新:这与制作雅虎的最佳方式是什么?媒体播放器自动启动,jQuery?等应该已经有了点击媒体的事件处理程序,那么怎么来 .click(),这与触发器('click'),没有触发该事件处理程序?

Update: this is related to What is the best way to make the Yahoo media player autostart, jQuery? and so there should already be event handler for clicking on a media, so how come .click(), which is the same as trigger('click'), not firing off that event handler?

推荐答案

调用 click()方法不会模拟单击链接。它会在受影响的元素上调用任何 click()处理程序。这是一个微妙但重要的区别。如果你想模拟点击链接,就没有可行的跨浏览器方式来做这件事。

Calling the click() method does not simulate clicking the link. It calls any click() handlers on the affected element(s). That's a subtle yet important difference. If you want to simulate clicking the link, there is no realiable cross-browser way of doing this.

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

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