我来到了路障,我希望有人可以解释我的错误。我会尽力解释我的剧本,对不起,如果我过分分解它。
我在page1.html上有一个div,它被page2.html上的div替换为jquery&#39; s .load()。我在<head>
中找到的脚本如下:
<script>
$(document).ready(function(){
$(".info").click(function(event){
var gallery = event.target.id;
$("#replace").load( "folio/" + gallery + ".html #grab", function () {
jQuery("#gallery").unitegallery({
theme_enable_preloader: true,
tiles_col_width: 250,
tiles_space_between_cols: 10,
tiles_min_columns: 1,
tile_enable_image_effect:true,
tile_image_effect_type: "blur",
tile_image_effect_reverse: true,
lightbox_show_numbers: false,
lightbox_top_panel_opacity: true,
lightbox_overlay_opacity:1
});
$("#return").on("click", function(){
$("replace").load(" Portfolio1.html #replace1") });
});
});
});
</script>
单击<a id="folio1" class="info">
时执行脚本。变量库将存储已单击的<a id="folio1" class="info">
的id值。然后,我选择<div id="replace">
将通过Jquery的.load()
更新其内容。存储id的变量gallery
将在.load
内使用,以确定将从中加载新内容的相应页面URL。到目前为止,这完美无缺。
.load()
成功后,我创建了一个执行.unitegallery()
的回调函数。 Unitegallery()
成功执行并精美地创建了图库。在unitegallery()之后,我有另一个函数在.on("click"
上使用<a id="return">
等待点击事件。此函数将执行另一个.load
,它将<div id="replace">
返回其先前的状态。 这是事情停止工作的时候。
注意:用于功能<a id="return">
的选择器已通过第一个.load()
插入到网页中。
问题:此.on("click"
未执行。
关于为什么脚本部分没有执行的想法? <a id="return">
是否无法选择第一个.load()
加载到文档中?
向我提问以获得澄清! :)
答案 0 :(得分:1)
如果有效,请参阅下面的评论。
$("#return").on("click", function(){
$("replace").load(" Portfolio1.html #replace1") // you need the # because i think the event registration will not recognize 'replace'
//enter code here`
});
此外,如果这不起作用,您可以粘贴您的HTML,以便我们可以看到您的文档的结构。
我还想指出,当事件注册移出加载范围时没有任何错误。