【问题标题】:External html file not showing for local client side include本地客户端未显示的外部 html 文件包括
【发布时间】:2015-06-11 19:37:44
【问题描述】:

我有一个 index.html 文件,我正在尝试使用 JavaScript 为我的页脚添加客户端包含。但是,我的“footer.htm”包含没有显示,只有文本显示。我很确定我的 JavaScript 代码有问题。我知道我的 footer.htm 文件没有问题。请帮忙!

document.write('footer.htm');
<div id="Footer">
  <script type="text/javascript" language="javascript" src="footer.js">
  </script>
</div>

【问题讨论】:

  • document.write 会将您提供的字符串写入文档。它不包括页面中的文件。要执行您需要的操作,您应该使用服务器端包含(如果在您的主机上可用)或 AJAX。

标签: javascript jquery html include client-side


【解决方案1】:

假设你正在使用 jQuery

<script type="text/javascript">
    $(document).ready(function(){
       $('#footer').load('footer.htm');
    });
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 2013-02-24
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 2011-04-24
    相关资源
    最近更新 更多