2013-04-05 131 views
2

我知道,使用rails和django,你可以使用模板将页眉和页脚一次写入一个单独的文件,并将其包含在所有网页中。我想知道,像这样的东西可以用jQuery或html5来实现吗?如果是这样,怎么样?如何使用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> 

回答

4

雅,如果你使用jQuery的​​函数。我认为它会看起来像

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

而且应该这样做。

Documentation available here

你不能这样做的唯一的事情就是让HTML代码,因为“同源策略”的另一个领域,我相信这是防止CSRF攻击和/或会话劫持。

+0

谢谢,这正是我一直在寻找的! – thedeepfield 2013-04-05 18:50:51

+0

很酷,很高兴帮助! – OneChillDude 2013-04-05 20:38:22

相关问题