Jquery Mobile Same Footer on Different Pages

三世轮回 提交于 2019-11-30 14:47:44

Try with following event, it works with my code:

$('[data-role=page]').live('pageshow', function (event, ui) {
            $("#" + event.target.id).find("[data-role=footer]").load("footer.html", function(){
                $("#" + event.target.id).find("[data-role=navbar]").navbar();
            });
        });

This gist shows the entire code.

skhurams

from jquery 1.9 and above live is now deprecated please use the function with on. In console it will give TypeError: $(...).live is not a function

example change your code

$('[data-role=page]').live('pageshow', function (event, ui) {
            $("#" + event.target.id).find("[data-role=footer]").load("footer.html", function(){
                $("#" + event.target.id).find("[data-role=navbar]").navbar();
            });
        });

Replace with

 $('[data-role=page]').on('pageshow', function (event, ui) {
                $("#" + event.target.id).find("[data-role=footer]").load("footer.html", function(){
                    $("#" + event.target.id).find("[data-role=navbar]").navbar();
                });
            });

You need to load the external html code to an div with a data-role="footer", so you need to change the:

<div class="footerExt"></div>

to

<div data-role="footer" class="footerExt"></div>

and for example your footer html could have a h3

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