jQuery Mobile: Use same header footer for all pages

前端 未结 3 2286
陌清茗
陌清茗 2021-02-20 16:13

I\'m trying to implement some code that will create the headers and footers on all of my web pages instead of hard coding them. I tried this:

I had this in my \"main pag

3条回答
  •  借酒劲吻你
    2021-02-20 16:43

    I use .clone()

    In my multipage jQuery Mobile project I have a header on my main page:

    
    

    and in all the subsequent pages (or divs with data-role=page) I have this:

    and then on pageinit you clone the master and append to all the children:

    $(document).delegate("#index", "pageinit", function () {
           $("#headerMaster").clone().appendTo(".headerChild");
    });
    

    EDIT: if pageinit doesn't work for you, try the pagebeforecreate event

    $(document).delegate("#index", "pagebeforecreate", function () {
         $("#headerMaster").clone().appendTo(".headerChild");  
    });
    

提交回复
热议问题