[英]jQueryTOOLS Overlay lightbox not functioning when HTML/LINK is loaded via ajax
在开始之前,我已经研究并找到了类似的先前问题: 重新初始化jQuerytools在ajax加载的元素上覆盖
但是,对该问题的“答案”建议使用.live()。 我尝试向我们提供jQuery 1.9 .live()不是使用.on()更新的功能 。
$(".overlay_load[rel]").on('click', 'a', function () {
$(this).overlay().load();
$(this).overlay().load();
return false;
});
我会承认,除了重新初始化新加载的HTML以便jQueryTOOLS Overlay可以“访问”新加载的HTML之外,我不是100%确切地了解正在做什么。
我有一个页面通过AJAX加载HTML内容部分。 这是一个加载的DIV的示例。
<div class="ajax-returned mytop">
<span class="username"> drkwong </span> <br>
<span class="full-name">Andrew Kwong</span><br>
<span class="action-status">
<span class="mt-icon ut3"></span>
<span class="autoship active">A</span>
<span class="view_profile">
<a href="/member/downline_tree_view/?view=tree_profile&program=1&view_userid=13" rel="#overlay">
<img src="/inc/downline_tree/images/more_info.png" rel="#13">
</a>
</span>
</span>
</div>
<!-- overlayed element -->
<div class="apple_overlay" id="overlay">
<!-- the external content is loaded inside this tag -->
<div class="contentWrap"></div>
</div>
这有一个链接,该链接应使用jQuery,然后加载jQueryTOOLS叠加灯箱:
<script>
$(function() {
// if the function argument is given to overlay,
// it is assumed to be the onBeforeLoad event listener
$("a[rel]").overlay({
mask: 'grey',
effect: 'apple',
onBeforeLoad: function() {
// grab wrapper element inside content
var wrap = this.getOverlay().find(".contentWrap");
// load the page specified in the trigger
wrap.load(this.getTrigger().attr("href"));
}
});
});
</script>
这是我用来将外部页面加载到灯箱中的jQuery: http : //jquerytools.github.io/demos/overlay/external.html
感觉就像没有触发jQuery。
这是标题中的内容:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="/templates/public/2/downline/js/jquery.browser.min.js"></script>
<script type="text/javascript" src="/templates/public/2/downline/js/jquery.tools.min.js"></script>
jQueryTOOLS Overlay需要使用jquery.browser.min.js来访问浏览器。 https://github.com/gabceb/jquery-browser-plugin
编辑:
AJAX
var ids=new Array()
var node
var param={"action":"NodeDetailAll","admin":"1"}
var users=new Array()
function get_ids(){
for(var i=0;i<nodes.length;i++){
users.push("child_"+$(nodes[i]).attr("class"))
ids.push($(nodes[i]).attr("class"))
}
}
function get_nodes(){
nodes = $("#chart [myattr*='descendent']")
nodes= jQuery.makeArray(nodes);
$.when(get_ids()).then(function(){
$.each(ids,function(key,value){
param[users[key]]=value
})
})
}
function write_html(response){
$.each(response,function(key,value){
$("."+key).html(value)
})
}
jQuery(document).ready(function() {
$(".spinner-loader").fadeIn(200)
$.when(get_nodes()).then(function(){
$.post("~ajax_url~",param,function(response) {
response=jQuery.parseJSON(response)
$.when(write_html(response)).done(function() {
$(".spinner-loader").fadeOut(600)
$("#chart").css("opacity","1")
// is this where I would add the on()? //
// I tried that, without success. //
// perhaps I need to modify the on() function? //
})
})
})
})
您可以在ajax函数的回调中调用覆盖绑定。 另一件事是检查您的jQuery选择器,以确保已正确配置它们,并选择了将事件绑定到的适当元素。
按照jQuery文档的规定:“事件处理程序仅绑定到当前选定的元素;在代码调用.on()时,它们必须存在于页面上。”
因此在我看来,在您的AJAX请求的回调中调用绑定功能将是可行的方法! 也许如果您可以提供代码的简化版本,包括ajax请求,那么我可以尝试再看看:)
使用其他解决方案。 jQueryTOOLS Overlay不再处于活动状态,并使用已弃用甚至取消的jQuery函数。 就所有这些问题而言,试图解决所有这些问题都被证明效率低下,而且就AJAX而言,这是最新版本的jQuery无法实现的。
如@sparky所建议,FancyBox 2提供了所需的解决方案。 实施起来既简单又直观。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.