单击事件仅适用于页面加载后的第一次单击
我使用这个 jquery 弹出插件并得到一些奇怪的行为。我已联系创建者,但没有得到答复,想在这里询问我的代码是否存在任何一般问题。
设置: 在新选项卡中打开页面的常规 html 链接(适用于禁用 JS 的用户)。
下面的 js 捕获链接点击并动画弹出窗口,而不是跟随链接。
问题: 它在每个页面加载时第一次单击时起作用,但随后单击则跟随 href 。
js
$("a[class*='popupbox-link']").live("click",function (e) {
if($("#popupbox").length == 0){
$('body').append('<div id="popupbox"><a class="bClose">Stäng</a><div id="pContent"></div></div>');
}
var url = this.href;
$("#popupbox").bPopup({contentContainer:'#pContent', loadUrl: url });
e.stopPropagation();
return false
});
I use this popup plugin for jquery and get some strange behaviour. I have contacted the creator but got no answer and would like to ask here if there is any general problem with my code.
The setup:
Regular html links that open a page in a new tab (for JS disabled users).
The js below to catch the link click and animate a popup instead of following the link.
The problem:
It works the first click on every page load but therafter a click follows the href instead.
js
$("a[class*='popupbox-link']").live("click",function (e) {
if($("#popupbox").length == 0){
$('body').append('<div id="popupbox"><a class="bClose">Stäng</a><div id="pContent"></div></div>');
}
var url = this.href;
$("#popupbox").bPopup({contentContainer:'#pContent', loadUrl: url });
e.stopPropagation();
return false
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 delegate 而不是 live
try using delegate instead of live
尝试阻止事件传播
Try to prevent the event propagation