0

I'm attempting to use jQuery mobile to create a new page, with a dynamically generated header. However, when I do this, my header is never enhanced.

My javascript is as follows:

var create_new_page = function(){
    var new_page = jQuery('<div>').attr('class', 'mypage').attr('id', 'new-page').data('role','page'); 
    var nav_bar = jQuery(<div data-role="navbar"><h1>THIS SHOULD BE A NAVBAR</h1></div>
    new_page.appendTo(jQuery('body')).trigger("create");
    new_page.ready(function(){
        jQuery.mobile.changePage(new_page);
    });
}
jQuery( document ).delegate("#loading", "pageinit", function() {
   create_new_page();
});

You can the exact code I am working with for this at http://jsfiddle.net/KAWtE/2/

I would appreciate if you did not suggest calling .page() or .trigger("create") on random elements without testing it in fiddler. I've attempted to call these functions on every combination of elements and containers to no avail.

Thank you for your help!

4

1 に答える 1

0

は機能しdata('role','page')ていません。交換すれば

var new_page = jQuery('<div>').attr('class', 'mypage').attr('id', 'new-page').data('role','page');

var new_page = jQuery('<div data-role="page">').attr('class', 'mypage').attr('id', 'new-page');

できます。( http://jsfiddle.net/KAWtE/3/をいじっています)

于 2012-05-02T18:47:34.013 に答える