繁体   English   中英

将innerhtml替换为外部页面

[英]Replace innerhtml with external page

我有一个页面,包含一个用于导航的标题div,一个用于内容的内容div,以及一个只有一些静态信息的页脚div。

我们的想法是,当您单击标题栏中的内容时,内容div会相应地更改其内容。 我想将每个内容元素存储在自己的文件中,以便于开发。 我怎样才能填写下面写的这个magicLoad函数?

我目前没有使用任何框架(jquery浮现在脑海中),但我肯定不反对使用它。 如果我在这里违反了其他最佳做法,我也很想知道,但我的主要目标是从外部页面加载。 我怎样才能做到这一点?

这是我现在设置的基本骨架模型。 (当然,这不仅仅是那3个,但这些足以说明这一点。)

<html>
    <script type="text/javascript">
    function show(which) {
        document.getElementById(which).innerHtml = magicLoad(which + ".html");
        return false;
    }       
    function showHome() { show('home'); return false;} // for onload

    </script>
    <body>
    <div id="header">
        <a href="javascript:void(0)" onclick="show('home')">HOME</a> |
        <a href="javascript:void(0)" onclick="show('training')">TRAINING</a> |
        <a href="javascript:void(0)" onclick="show('audits')">AUDITS</a>
    </div>
    <div id="content">

    </div>
    <div id="footer">

    </div>
    </body>
    <script> window.onload=showHome; </script>
</html>

使用以下,简单直接

$('#which').load('test.html');

如果哪个作为参数

$('#'+which).load('test.html');

如果您想将其他网页嵌入其中,您应该考虑使用<iframe> 就像是:

<script type="text/javascript">
function show(which) {
    document.getElementById(which).src=which+".html";
    return false;
}       
function showHome() { show('home'); return false;} // for onload

</script>
<iframe id="home"></iframe>

暂无
暂无

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

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