【问题标题】:How to add a html file into another html file?如何将一个html文件添加到另一个html文件中?
【发布时间】:2016-09-08 06:18:51
【问题描述】:

假设我有一个 html 文件 - “ma​​in.html” & 另一个 html 文件“content.html

我想在 main.js 上添加内容。我做了内容,在哪里

 content's - Width = window.innerWidth || root.clientWidth || body.clientWidth;
    Height = window.innerHeight || root.clientHeight || body.clientHeight;

内容是绝对的。 而且我不知道main的高度宽度。

我在正文部分添加了主要内容 -

&这发生了—— enter image description here 这里罐头来自内容,文本来自主要..

问题是内容带有自己的滚动条..

怎么办...!?

【问题讨论】:

  • 那是 iframe 还是什么?
  • 你正在处理的一些代码怎么样?
  • 主要我在正文部分添加 -
  • 欢迎来到 SO!请使用标准的国际英语,其中句子以大写字母开头,单词“I”大写,句子以一个句号(句号)结尾。此外,您无需提前感谢人们阅读您的问题。

标签: html css


【解决方案1】:

要动态加载内容,您可以使用 XMLHttpRequest() 进行 AJAX 调用。

在本例中,将一个 url 传递给 loadPage() 函数,在该函数中返回加载的内容。

<!DOCTYPE html>
<html lang="en">
    <head>
        <script type="text/javascript">
            function loadPage(href)
            {
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.open("GET", href, false);
                xmlhttp.send();
                return xmlhttp.responseText;
            }
        </script>
    </head>

    <body>
        <div onClick="document.getElementById('bottom').innerHTML = 
                      loadPage('content.html');">Home</div>

        <div id="bottom"></div>
    </body>

</html>

当单击包含“Home”文本的 div 元素时,它将 id 为“bottom”的 div 元素的 html 设置为在相同相对位置的“hello-world.html”文档中找到的内容。

content.html

<p>Your content</p>

【讨论】:

  • 对不起,不起作用..只有“主页”出现在顶部的 main.html 中,无法点击..
猜你喜欢
  • 2017-01-25
  • 2011-09-13
  • 1970-01-01
  • 2017-08-18
  • 1970-01-01
  • 1970-01-01
  • 2011-11-24
  • 2017-04-06
相关资源
最近更新 更多