![](/img/trans.png)
[英]Binding multiple events (resize and load) to addEventListener (JQuery)
[英]conflict multiple .load() events of jquery
我已经使用$('#result').load('test.php')
文件加载数据,该文件完全正常工作。
这是test.php
屏幕截图
现在这是我在灯箱中加载的文件:
在我的test.php
文件中,我还在点击事件的灯箱中加载了另一个文件。 灯箱在新加载的文件中正确显示。 这是调用lighbox的代码:
jQuery('#wt_opp_coll .coun').click(function(){
jQuery(this).jpLightBox({
width: 500,
height: 250,
url: 'components/content/test_file.php'
//message: 'Just Testing the file'
});
});
这个我的新加载文件test_file.php
出现在灯箱中,但是我上次加载的文件test.php
在灯箱上消失了,正如你在第二个屏幕截图中看到的那样,只有灯箱不会出现像第一次屏幕截图那样的背景细节。
请帮我停止消失我上次加载的文件( test.php
)。
注意:我还在lighbox中使用.load .load()
函数来加载url。
我没有对LightBox做过任何事情,但问题是你用新的灯箱替换#wt_opp_coll .coun
?
jQuery('#wt_opp_coll .coun').click(function(){
jQuery(this).jpLightBox({
width: 500,
height: 250,
url: 'components/content/test_file.php'
//message: 'Just Testing the file'
});
});
第二行有jQuery(this)
,表示父亲#wt_opp_coll .coun
。 所以我认为正在发生的事情是灯箱正在取代#wt_opp_coll .coun
内容。
我不能告诉你是什么导致这个奇怪的问题,但我也有一个问题,一段时间后。 我解决它的方法是使用livequery来处理我的点击事件。 不要问我为什么,我已经浏览了几个小时的图书馆和文档,并试图找到别人的答案无济于事。
试一试,如果使用livequery没有问题,它可能是你的解决方案。
这是我的代码片段,它用于最多50个不同的加载调用实例,所有这些都可以工作。 有些是由其他加载数据动态创建的链接。
function ajaxContent(link, sel, reg, extReg) {
$(sel).not(link).removeClass("active");
$(link).addClass("active");
var toLoad = $(link).attr('href')+ ' ' + extReg;
$(reg).fadeOut('slow',loadContent);
function loadContent() {
$(reg).load(toLoad,'',showNewContent())
}
function showNewContent() {
$(reg).delay(200).fadeIn('slow');
}
}
$(document).ready(function() {
// Top left "main" nav
$('#jax-nav li a').livequery("click", function(event) {
ajaxContent(event.target, '#jax-nav li a', '#page-content', '#ajax-out');
return false;
});
尝试在你的html上为灯箱放置一个空div
<div id="lightBoxDiv"></div>
并编辑您的代码
jQuery('#wt_opp_coll .coun').click(function(){
jQuery("#lightBoxDiv").jpLightBox({
width: 500,
height: 250,
url: 'components/content/test_file.php'
//message: 'Just Testing the file'
});
});
你还需要在关闭按钮上刷新这个div的内容,否则它会影响你的基本html
将此代码放在关闭按钮中
$("#lightBoxDiv").html('');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.