我遇到了障碍,我希望有人能解释我的错误在哪里。我会尽我所能解释我的剧本,如果我过度分解它,我很抱歉。
我在 page1.html 上有一个 div,它正在通过 jquery 的 .load() 替换为 page2.html 上的一个 div。我的脚本在 <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()
更新其内容.变量 gallery
存储 id 的那个将在 .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()
加载到文档中无法被选中?
向我提问以澄清问题! :)
最佳答案
如果有效,请在下方查看我的评论。
$("#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,以便我们可以看到您的文档的结构。
我还想指出,将事件注册移出加载范围并没有错。
关于javascript - .load() 后回调函数不执行点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41866606/