Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jQuery或HTML5在所有页面上复制页眉和页脚?_Jquery_Html_Navigation_Footer_Dry - Fatal编程技术网

如何使用jQuery或HTML5在所有页面上复制页眉和页脚?

如何使用jQuery或HTML5在所有页面上复制页眉和页脚?,jquery,html,navigation,footer,dry,Jquery,Html,Navigation,Footer,Dry,我知道使用rails和django,您可以使用模板将页眉和页脚作为单独的文件编写一次,并将其包含在您的所有网页中。我想知道,仅仅用jQuery或html5就可以实现这样的功能吗?如果是,怎么做 <html> <head></head> <body> <navigation> include code from header.html here </navigation> ...

我知道使用rails和django,您可以使用模板将页眉和页脚作为单独的文件编写一次,并将其包含在您的所有网页中。我想知道,仅仅用jQuery或html5就可以实现这样的功能吗?如果是,怎么做

<html>
    <head></head>
    <body>
        <navigation> include code from header.html here </navigation>
        ...
        some page specific content
        ...
        <footer>include code from footer.html here</footer>
    </body>
</html>

在此处包含header.html中的代码
...
某些特定于页面的内容
...
在此处包含footer.html中的代码

Ya,如果您使用jQuery的
.load()
函数。我想它看起来像

$('footer').load('/assets/myfooter.html')

这应该可以做到


由于“同源策略”,您唯一不能做的就是从另一个域获取html,我认为这是为了防止CSRF攻击和/或会话劫持。

Ya,如果您使用jQuery的
.load()
函数。我想它看起来像

$('footer').load('/assets/myfooter.html')

这应该可以做到


由于“同源策略”,您唯一不能做的就是从另一个域获取html,我认为这是为了防止CSRF攻击和/或会话劫持。

谢谢,这正是我想要的!谢谢,这正是我想要的!