JQuery Mobile, one footer fragment for whole site

旧城冷巷雨未停 提交于 2019-12-04 16:59:19

module.html

<!DOCTYPE html>
    <html lang="ja">
    <head>
        <meta charset="UTF-8">
    </head>
    <body>
        <div data-role="page">
            <div data-role="header">
                <h1>module header</h1>
            </div>
            <div data-role="footer" class="ui-bar">
                <h3>module footer</h3>
            </div>
        </div>
    </body>
</html>

module.js (load this in all pages)

function module() {
    var fthtml = $('#module :jqmData(role="footer")').clone();
    $(':jqmData(role="footer")').remove();
    $(':jqmData(role="page")').append(fthtml).page().trigger('pagecreate');
}

$(function(){
    $('body').append('<div id="module"></div>');
    $('#module').load('YOUR_module.html_PATH :jqmData(role="page")',function(){
        $($(this).html()).replaceAll(this).attr('id','module');
        module();
    });
    $(':jqmData(role="page")').live('pageinit',module);
});

YOUR_module.html_PATH (eg. "../module.html", "../module/module.html")

If you are generating HTML pages server side, You can use your server language (php,java,node) templating capabilities to insert a HTML from common file.

i.e. for jsp

    </div>
    <jsp:include page="scripts/footer.jsp" />
    .....
</body>

And if you are doing heavy stuff in javascript than use any javascript templating engine. ie.e http://handlebarsjs.com/

I solved this by creating partial footer view and calling it where I need it: @Html.Partial("Footer")

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!