jQuery 触发器事件多次触发

发布于 2024-09-16 05:11:51 字数 504 浏览 3 评论 0原文

我试图在页面加载时加载 jQuery 灯箱。我已经走了一半了。页面加载时灯箱会打开,但随后会在同一窗口中作为完整页面打开链接。在将链接加载到单独的窗口中之前,如何让它停止在此时。

jQuery:

$(document).ready(function(){
  $("a.greybox").bind("click", openbox);
  $("a.greybox").trigger('click', openbox);

  function openbox(){
    var t = this.title || $(this).text() || this.href;
    GB_show(t,this.href,340,220);
  }
})

HTML:

<a href="http://google.com/" title="Google" class="greybox">Launch Google</a>

I'm trying to get a jQuery lightbox to load up when a page loads. I got half way there. The lightbox opens when the page loads but then proceeds to open the link in the same window as a full page. How do I get it to stop at this point before loading the link in a separate window.

jQuery:

$(document).ready(function(){
  $("a.greybox").bind("click", openbox);
  $("a.greybox").trigger('click', openbox);

  function openbox(){
    var t = this.title || $(this).text() || this.href;
    GB_show(t,this.href,340,220);
  }
})

HTML:

<a href="http://google.com/" title="Google" class="greybox">Launch Google</a>

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

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

发布评论

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

评论(2

猫瑾少女 2024-09-23 05:11:51

包含以下行:

return false;

如果您在函数中 这将阻止链接原始行为的触发。

If you include the line:

return false;

in your function. That will stop the links original behaviour from firing.

感性 2024-09-23 05:11:51
function openbox(evt){
    evt.preventDefault(); // <<-- Add this
    var t = this.title || $(this).text() || this.href; 
    GB_show(t,this.href,340,220);}
}
function openbox(evt){
    evt.preventDefault(); // <<-- Add this
    var t = this.title || $(this).text() || this.href; 
    GB_show(t,this.href,340,220);}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文