触发()和triggerHandler()与“点击”,在页面加载时触发厚盒

发布于 2024-12-10 10:59:56 字数 452 浏览 6 评论 0原文

我试图在页面加载的链接上触发单击事件。我目前正在这里处理此代码 http://jsfiddle.net/QPPbA/

$(document).ready(function(){
   $('#trigger-me').trigger('click'); 
});

<a href="http://www.stackoverflow.com" target="_blank" id="trigger-me">trigger hidden</a>

但它不起作用。我在这里缺少什么?

编辑
我想在页面加载时触发一个厚盒,我得到了一些代码,但它只显示黑色“色调”..所以我想我会像这样触发它,但这种方式也不起作用..有什么建议吗?

im trying to trigger a click event on a link on the page load. im currently working on this code here http://jsfiddle.net/QPPbA/

$(document).ready(function(){
   $('#trigger-me').trigger('click'); 
});

<a href="http://www.stackoverflow.com" target="_blank" id="trigger-me">trigger hidden</a>

but it does not work. what im i missing here?

EDIT

I would like to trigger a thickbox on page load, i got some code but it only shows the black "tint".. so i thougth i would trigger it like this but this way does not work either.. any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故事还在继续 2024-12-17 10:59:56

它没有点击事件...

$(document).ready(function(){
    $('#trigger-me').click(function() {
        window.location.href = $(this).attr("href");
    });
    $('#trigger-me').trigger('click'); 
});

更新: jsfiddle

It hasn't got a click event...

$(document).ready(function(){
    $('#trigger-me').click(function() {
        window.location.href = $(this).attr("href");
    });
    $('#trigger-me').trigger('click'); 
});

update: jsfiddle

萌酱 2024-12-17 10:59:56

当您使用 JavaScript 触发事件时,不会调用浏览器对该事件的默认操作。在这种情况下,当您触发链接上的 click 事件时,它不会导致导航。

如果您想将访问者重定向到另一个页面,可以使用 window.location

window.location = $("#trigger-me").prop("href");

When you trigger an event with JavaScript, the browser's default action for that event isn't invoked. In this case, it won't cause a navigation when you trigger the click event on a link.

If you want to redirect the visitor to another page, you can use window.location:

window.location = $("#trigger-me").prop("href");
闻呓 2024-12-17 10:59:56

尝试这个作为替代:

$(document).ready(function(){
   window.location = $('#trigger-me').attr('href');
});

Try this as alternative:

$(document).ready(function(){
   window.location = $('#trigger-me').attr('href');
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文