如何将html加载到“皮肤"中那也已经从外部html文件加载了? [英] How to load html into a "skin" that has also been loaded from an external html file?

查看:109
本文介绍了如何将html加载到“皮肤"中那也已经从外部html文件加载了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将html加载到还从外部html文件加载的皮肤(带有导航按钮的页眉/页脚)中.这是jsfiddle中的代码,尽管它无法工作,因为我无法将两个外部文件放入jsfiddle中:

I'm trying to load html into a skin (header/footer with nav buttons) that has also been loaded from an external html file. Here's the code in jsfiddle although it won't work because I can't put the two external files into jsfiddle:

http://jsfiddle.net/J4yUt/1/

这是两个外部文件中的内容:

This is the content in the two external files:

medbox.html:

medbox.html:

<div id="medBox"></div>

smallBox.html:

smallBox.html:

<div id="smallBox"></div>

当我单击按钮时,中号框出现在大框中,但是小号框没有出现在中号框中.我认为要加载smallbox.html的代码是在medBox.html完全加载之前执行的,那么如何让它等待medBox.html完全加载?

When I click the button, the medium box appears in the big box, but the small box doesn't appear in the medium box. I think the code to load the smallbox.html executes before the medBox.html has fully loaded, so how do I get it to wait for the medBox.html to fully load?

这就是我想要的结果:

http://jsfiddle.net/Sv4yf/2/

推荐答案

$("#bigBox").load("medBox.html", function(){
   $("#medBox").load("smallBox.html");
});

在第一个加载处理程序中使用回调函数.

Use a callback function in your first load handler.

了解更多: http://api.jquery.com/load

这篇关于如何将html加载到“皮肤"中那也已经从外部html文件加载了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆