我的网站有固定的页眉和页脚组件。我在正文页面上有一个链接。当我点击链接时,它应导航到另一个页面而不更改页眉和页脚组件。任何人都知道如何使用jquery / javascript实现它。
答案 0 :(得分:0)
您可以直接将XMLHttpRequest用于所需的html页面,如下所示:
function load_htm()
{
var xml = new XMLHttpRequest();
//here your content to be loaded
var elem = document.getElementById('content');
//here goes your target html file...
url = "/yourfile.htm";
//this is not the better way to, but will clear the element...
elem.innerHTML = '';
if (xml !== null) {
xml.open('GET', url, true);
xml.send();
xml.onreadystatechange = function() {
if (xml.readyState === 4) {
//getting the results and assign to element
response = xml.responseText;
elem.innerHTML = response;
}
}
}
}
HTML:
<div id="footer"></div>
<div id="link" onclick="load_htm();"></div>
<div id="content"></div>
<div id="header"></div>