触发点击 jquery 不起作用
我正在弄清楚为什么这个简单的脚本不起作用:
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('.next_button a').trigger('click');
});
noConflict
是必要的,因为我还在该页面中加载了prototype/scriptaculous。
如果我将 .trigger('click')
替换为另一个函数(例如: .css(...)
,效果很好。只有触发似乎被破坏了。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如何通过 jquery 模拟锚点点击?
检查此链接并查看
Stavanicus 的回答。
$('a#swaswararedirectlink')[0].click();
How can I simulate an anchor click via jquery?
Check this link and see
this answer by Stevanicus.
$('a#swaswararedirectlink')[0].click();
您只能触发 jQuery 创建的单击。这是 jQuery 可爱的小怪癖之一。
You can only trigger a click that jQuery has created. It's one of jQuery's cute little quirks.
正如加里所回答的那样。下面的代码将不起作用。
但这会..:)
as what Gary has answered. the code below will not work.
but this will.. :)
我认为这个演示不会工作,但它确实有效(Chrome 12)。它将提醒
两条消息,每个点击事件一条消息。一个是由 jQuery 创建的,一个是本机的,但我认为只能触发 jQuery 事件。编辑: 是的,click
不跟随 < code>href.编辑2: 所以你要手动触发的事件实际上是由Prototype轮播插件创建的事件。对于下面的代码,我假设它是这个。如果是这种情况,为什么不能使用 Prototype 触发事件或本机......像这样:
此事件触发演示中有两个示例(其中一个已被注释掉,但您可以切换以获得相同的结果)。一种来自 用 Prototype 触发事件,它使用
event.simulate.js
和一个使用 fakeClick() 函数href="https://stackoverflow.com/questions/1421584/how-can-i-simulate-a-click-to-an-anchor-tag/1421968#1421968">如何模拟对锚标记的点击?。其中任何一个在 Chrome 12 中都适合我。I thought that this demo would not work but it does (Chrome 12). It willalert
two messages, one for each click event. One is created by jQuery and one is native but I thought that only jQuery events could be triggered.Edit: Yes theclick
does not followhref
.Edit 2: So the event you want to manually trigger is actually an event created by a Prototype carousel plugin. For the code below I am assuming it is this one. If that is the case, why can't you just use fire the event using Prototype or natively… like this:
There are two examples in this demo of event firing (one is commented out but you can switch for the same result). One is from Trigger an event with Prototype which uses
event.simulate.js
and one using thefakeClick()
function from How can I simulate a click to an anchor tag?. Either of which is working for me in Chrome 12.