jQuery 切换 div 并链接到 colorbox(灯箱)
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在不确切知道灯箱触发器是什么的情况下不确定,但您是否尝试过添加
event.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?
确保在 Colorbox 脚本之前需要 Jquery 库
Ensure you have required Jquery Library before Colorbox script