jQuery Mobile中.mobile.loadPage和外部页面的问题 [英] Issues with .mobile.loadPage and external page in Jquery Mobile

查看:123
本文介绍了jQuery Mobile中.mobile.loadPage和外部页面的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的jquery移动应用程序中,我有一个页面要加载外部内容.

In my jquery mobile application I have one page that I want to load external content.

尝试遵循文档,并且我的代码不会产生任何脚本错误,但不会加载我的外部内容.

Trying to follow the docs, and my code doesn't produce any script errors, but my external content does not load.

    $(document).ready(function () {
        $.mobile.ajaxEnabled = false;

        //Initialize page container per docs 
        $("#staff-directory-container").pagecontainer({ defaults: true });

        //Get external content into DOM
        $.mobile.loadPage("http://another.domain.com/myContent.html", {
        pageContainer: $('#staff-directory-container')
            });

    });

在此先感谢您提供的任何帮助.... 克里斯

Thanks in advance for any help offered.... Chris

推荐答案

要绑定jQuery Mobile中的事件,请使用与.ready()等效的pagecreate.要加载外部页面,请使用 .pagecontainer("load", "target", { options }) ,因为不推荐使用.loadPage()在jQM 1.5中被删除.

To bind events in jQuery Mobile, use pagecreate which is equivalent to .ready(). To load an external page, use .pagecontainer("load", "target", { options }) as .loadPage() is deprecated and will be removed in jQM 1.5.

在您的情况下,$.mobile.pageContainer$("#staff-directory-container").并且请注意,应该启用.

In your case, $.mobile.pageContainer is $("#staff-directory-container"). And note that Ajax should be enabled.

$(document).on("pagecreate", "#pageID", function () {
  $("#loadBtn").on("click", function () {
    /* define new pagecontainer then load */
    $.mobile.pageContainer = $("#staff-directory-container").pagecontainer();
    $.mobile.pageContainer.pagecontainer("load", "myContent.html");
  });
});

这篇关于jQuery Mobile中.mobile.loadPage和外部页面的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆