且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery pagecontainer更改奇怪的行为?

更新时间:2021-12-16 01:14:52

更新

根据您更新的问题,使用JQM Ajax导航重定向将不会加载index.html或register.html中的任何库.所有库都应放置在运行首页的head中.

另一种选择是,如果希望将库与页面内容一起检索,请将库放置在index.html/register.html的 page div中.

Another option, place libraries inside page div of index.html/register.html if you want them to be retrieved along with page's content.

在单页模型中,jQuery Mobile解析每个外部文件的第一个 page div,而忽略其他任何内容.

In Single Page Model, jQuery Mobile parses first page div of each external file and neglects anything else.

由于每个页面中都有相同的菜单,因此应专门针对要创建的页面中的菜单.您无需为每个页面添加pagecreate侦听器,只需一步即可完成.

Since you have the same menu in each page, you should specifically target the menu within page being created. You don't need to add pagecreate listener for each and every page, it can be done in one step.

$(document).on("pagecreate", function (e) {

    /* created page */
    var createdPage = $(e.target);

    /* find element within it
       remove previous listener
       add new listener */

    createdPage.find("#item1").off("click").on("click", function () {
        $.mobile.pageContainer.pagecontainer("change", "item1.html");
    });

    createdPage.find("#item2").off("click").on("click", function () {
        $.mobile.pageContainer.pagecontainer("change", "item2.html");
    });

    /* rest of items */
});

演示

Demo