简体   繁体   English

如何匹配HTML页眉和页脚

[英]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

Regex Demo 正则表达式演示

For footer: 对于页脚:

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

Regex Demo 正则表达式演示

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

相关问题 提取html页面的页眉和页脚 - Extracting the header and the footer of html page 使用XPage或HTML打印页眉和页脚 - Print Header and Footer with XPage or HTML 如何在 static ZFC35FDC70D5FC69D269883A82EZC 页面中使用默认 wordpress header 和页脚 - how to use default wordpress header and footer in static html page 如何一次将相同的页眉和页脚添加到所有页面? HTML - How to add the same header and footer to all pages at once? HTML 如何使用jQuery / JavaScript在HTML模板中分隔页眉页脚和侧边栏 - how to separate header footer and sidebar in a html template with jquery/ javascript 如何在HTML CSS Web应用程序中具有通用的页眉和页脚? - How to have a common header and footer in a HTML CSS web app? 如何在其他页面动态插入mainpage.html的header和footer? - How to dynamic insert the header and footer of mainpage.html on other pages? 如何创建页眉/页脚 - How to create Header/Footer 如何获取HTML文档以引用其他HTML文档中的“页眉”和“页脚”元素? - How do I get a HTML document to refer to the “header” and “footer” elements in other HTML documents? 使用单页时,如何在所有路线中同时添加header.html和footer.html? - How to add both a header.html and a footer.html to all your routes when using singlepage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM