jquery mobile - loadPage 问题 [英] jquery mobile - loadPage issue

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

问题描述

我无法让 jQuery-mobile 加载页面将我的下一个页面加载到content"div.

我已将我的页面精简到基本信息,这是代码.

index.html:

<头><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>JQuery 移动加载页面测试</title><link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"><script src="http://code.jquery.com/jquery-1.9.1.min.js"></script><script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script><身体><div data-role="页面"><div id="containerTest" data-role="content"><input type="button" id="nextPage" data-inline="true" value="加载第二页"/>

<!--/内容-->

<!--/page --><脚本>$( "#nextPage" ).on( "click", function(){$.mobile.loadPage("nextPage.html",{pageContainer: $('#containerTest')});});

nextPage.html

<p>这是下一页</p>

<!--/page -->

解决方案

我不认为你可以在另一个页面中加载一个页面,你可以尝试这样的事情:

$(document).on('pageinit', function(){$( "#nextPage" ).on( "点击", function(){$('#containerTest').load('nextPage.html [data-role="content"]',function(){$('.ui-page-active').trigger('create');});});});

这将从容器内的第 2 页加载内容(<div data-role="content">),然后它会触发原始页面上的 create 事件以增强加载的内容

I am having trouble getting jQuery-mobile load page to load my next page into the "content" div.

I have cut my page down to the basics and here is the code.

index.html:

<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>JQuery Mobile Load Page Test</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
</head>
<body>

<div data-role="page">

    <div id="containerTest" data-role="content">

        <input type="button" id="nextPage" data-inline="true" value="Load Second Page"/>

    </div> <!-- /content -->

</div> <!-- /page -->

<script>

    $( "#nextPage" ).on( "click", function()
    {
        $.mobile.loadPage("nextPage.html",
        {
            pageContainer: $('#containerTest')
        });
    });

</script>

</body>
</html>

and nextPage.html

<div data-role="page">

    <p>this is the next page</p>

</div> <!-- /page -->

解决方案

I don't think You can load a page inside another page, you could try something like this though:

$(document).on('pageinit', function(){
    $( "#nextPage" ).on( "click", function(){
        $('#containerTest').load('nextPage.html [data-role="content"]',function(){
            $('.ui-page-active').trigger('create');
        });
    });
});

This will load the content (<div data-role="content">) from page 2 inside the container, then it will trigger the create event on the original page to enhance the loaded content

这篇关于jquery mobile - loadPage 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆