[英]How to match HTML header and footer
I have the following script, where I parse entire HTML and bind to a div (Homepage): 我有以下脚本,在其中解析整个HTML并绑定到div(主页):
function htmlResponse() {
var res = "";
debugger;
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
options.async = true;
});
$.ajax({
url: "http://localhost:1469/Home.aspx",
success: function (result) {
res = result;
res = res.replace(/\/CMSPages\/GetResource\.ashx/g, 'http://localhost:1469/CMSPages/GetResource.ashx');
res = res.replace(/\/WebResource\.axd/g, 'http://localhost:1469/WebResource.axd');
res = res.replace('<ul>', '<ul class="fallback browse-experience-drop-down-width">');
$("#homePage").html(res);
}
}).done(function () {
});
};
res
variable contains full HTML which needs to be binds to div homepage. res
变量包含完整的HTML,需要将其绑定到div主页。
How I can write another regex which will fetch only <HEADER>
till </HEADER>
and <FOOTER>
till </FOOTER>
? 我如何编写另一个仅将
<HEADER>
提取到</HEADER>
和<FOOTER>
直到</FOOTER>
正则表达式?
And bind those two sections in two div tags? 并将这两个部分绑定到两个div标签中?
Something like below: 如下所示:
header = res.regex("REGEX FOR FETCHING HEADER");
footer = res.regex("REGEX FOR FETCHING FOOTER");
$("#HEADER").html(header);
$("#FOOTER").html(footer);
/<HEADER>(\n.*)*<\/HEADER>/g
应该可以。
You can try this. 你可以试试看
For header: 对于标题:
/<(?:HEADER|header)>([\s\S]*?)<\/(?:HEADER|header)>/g
For footer: 对于页脚:
/<(?:footer|FOOTER)>([\s\S]*?)<\/(?:footer|FOOTER)>/g
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.