jQuery 切换 div 并链接到 colorbox(灯箱)

发布于 2024-10-07 07:58:41 字数 698 浏览 0 评论 0原文

我有一个 div 可以切换其下方列表的可见性。在该主 div 中,我有一个链接,可打开一个 colorbox(jquery“lightbox”插件)以将新项目添加到列表中。

当然,当我单击该链接时,它除了切换列表(就像其父级一样)之外不会执行任何操作。所以我将 stopPropagation() 添加到链接中。它现在确实跟随链接,但它在父窗口而不是在颜色框中打开。

我该如何解决这个问题?谢谢 :)

<div class="list">
<div class="listname">
My List Name
<a href="my_link.html" class="colorbox">Add Item</a>
</div>
<div class="items">
My Items
</div>
</div>

$(".listname").toggle(
 function(){
  $(this).siblings(".items").slideDown(100);
  return false;
 },
 function(){
  $(this).siblings(".items").slideUp(100);
  return false;
 }
);

$(".listname a").click(function(e){ e.stopPropagation();  });

I have a div that toggles the visibility of the list below it. Within that main div, I have a link that opens a colorbox (jquery "lightbox" plugin) to add a new item to the list.

Of course, when I click the link, it doesn't do anything but toggle the list (like its parent). So I added the stopPropagation() to the link. It does follow the link now, but it opens in the parent window instead of in the colorbox.

How do I fix this? Thank you :)

<div class="list">
<div class="listname">
My List Name
<a href="my_link.html" class="colorbox">Add Item</a>
</div>
<div class="items">
My Items
</div>
</div>

$(".listname").toggle(
 function(){
  $(this).siblings(".items").slideDown(100);
  return false;
 },
 function(){
  $(this).siblings(".items").slideUp(100);
  return false;
 }
);

$(".listname a").click(function(e){ e.stopPropagation();  });

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

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

发布评论

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

评论(2

一城柳絮吹成雪 2024-10-14 07:58:42

在不确切知道灯箱触发器是什么的情况下不确定,但您是否尝试过添加

event.preventDefault();

防止以下链接?

$(".listname a").click(function(e){ 
    e.stopPropagation();
e.preventDefault();
});

Not sure exactly without knowing exactly what the lightbox trigger is but have you tried adding

event.preventDefault();

to prevent the following of the link?

$(".listname a").click(function(e){ 
    e.stopPropagation();
e.preventDefault();
});
奶气 2024-10-14 07:58:42

确保在 Colorbox 脚本之前需要 Jquery 库

<script src="/js/jquery.js" type="text/javascript">
<script>
 jQuery('a.colorbox').colorbox();
</script>

Ensure you have required Jquery Library before Colorbox script

<script src="/js/jquery.js" type="text/javascript">
<script>
 jQuery('a.colorbox').colorbox();
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文