繁体   English   中英

将 HTML 页面包含到另一个 HTML div 不起作用

[英]Include HTML page into another HTML div not working

好的 - 这让我发疯了。 如此简单的负载,但什么也没有发生。 有什么想法可以解决这个问题吗? 理想情况下,我想创建组件( header / 页脚 / 等)以在所有组件中重用。

这是我用于测试的 HTML。

<html>

<head>
 <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>

 <script>
   $(document).ready(function() {
     $("#included-page").load("test.html");
   });
 </script>

</head>

<body>
 <div id="included-page"></div>
 <!-- insert page 2 test -->
 <h1>This Page 1</h1>
</body>

</html>

这是我要加载的测试页面

<!doctype html>
<html>
<head>
</head>
<body>
<p>Included from page test</p>
</body>
</html>

我会发现使用include语句更容易,因为不需要 javascript:

<html>

<head>
 <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>

 <script>
   $(document).ready(function() {
     $("#included-page").load("test.html");
   });
 </script>

</head>

<body>

 <!--#include virtual="test.html"-->

 <h1>This Page 1</h1>
</body>

</html>

注意:这不是注释,但包含语句的格式与 HTML 注释的格式相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM