1.PHP+JQ+HTML
HTML
<div id="header"> <img src="loading.gif" alt=""> //等待的gif图 </div> <div id="main"> <h3>首页</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus amet architecto asperiores culpa error, maiores natus neque officiis perspiciatis repellendus sed sunt. Eius eos molestias nihil placeat possimus sit veniam.</p> </div>
PHP
header("Content-Type:text/html;charset=UTF-8"); //设置响应头 ?> <hr> //输出HTML代码 <p id="copyright">版权所有© 2017-10-11</p>
JQ
<script> $(document).ready(fn)/*页面加载完成后实现*/ $(function(){ /*页面加载完成后实现*/ $("#header").load("footer.php") }) </script>
输出效果:
限制:
1.PHP返回的只能是HTML片段,(json返回不行哦)
2.(“#id”).load 会替换ID中的内容类似 innerHTML="",而不是innerHTML+="";