繁体   English   中英

如何匹配HTML页眉和页脚

[英]How to match HTML header and footer

我有以下脚本,在其中解析整个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变量包含完整的HTML,需要将其绑定到div主页。

我如何编写另一个仅将<HEADER>提取到</HEADER><FOOTER>直到</FOOTER>正则表达式?

并将这两个部分绑定到两个div标签中?

如下所示:

header = res.regex("REGEX FOR FETCHING HEADER");
footer = res.regex("REGEX FOR FETCHING FOOTER");

                $("#HEADER").html(header);
                $("#FOOTER").html(footer);
/<HEADER>(\n.*)*<\/HEADER>/g

应该可以。

你可以试试看

对于标题:

/<(?:HEADER|header)>([\s\S]*?)<\/(?:HEADER|header)>/g

正则表达式演示

对于页脚:

/<(?:footer|FOOTER)>([\s\S]*?)<\/(?:footer|FOOTER)>/g

正则表达式演示

暂无
暂无

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

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