在运行时添加Jquery Mobile Panel

时间:2013-03-12 14:20:17

标签: jquery jquery-mobile jquery-plugins

我正在尝试在我的应用程序中使用jquery移动面板导航菜单,当您单击页面上的菜单按钮时出现此菜单,从文档,我明白我应该将此菜单面板添加到每个页面。

由于我的页面也是在运行时添加的,因此我需要在创建页面时将菜单面板注入页面,我正在使用以下不起作用的代码:

var $menuElement = $("#menu");
if ($activePage.find($menuElement).length <= 0) {
    console.log("Adding menu");
    $menuElement.show().css({height:$(".fb-menu").find("li").size() * 5 + "px"});
    $menuElement.prependTo($activePage);
    $activePage.trigger('create');
    $activePage.trigger('update');
}

任何人都知道如何将我的菜单面板添加到动态添加的页面中?

1 个答案:

答案 0 :(得分:0)

请看一下我对此解决方案的其他答案:https://stackoverflow.com/a/15223926/1848600

这是你动态添加它的方法:

$(document).on('pagebeforeshow', '[data-role="page"]', function(){                
    $('<div>').attr({'id':'mypanel','data-role':'panel'}).appendTo($(this));
    $('<a>').attr({'id':'test-btn','data-role':'button'}).html('Click me').appendTo('mypanel');
    $.mobile.activePage.find('#mypanel').panel();
    $(document).on('click', '#open-panel', function(){   
         $.mobile.activePage.find('#mypanel').panel("open");       
    });    
});

实例:http://jsfiddle.net/Gajotres/pZzrk/

相关问题