如何在 jQuery mobile 多页模板结构中将第二页显示为默认页? [英] How to show the second page as the default page in a jQuery mobile Multi-page template structure?

查看:15
本文介绍了如何在 jQuery mobile 多页模板结构中将第二页显示为默认页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 jQuery mobile 多页模板结构中将第二页显示为默认页?

<div data-role="page" id="foo"><div data-role="header"><h1>Foo</h1>

<div data-role="内容"><p>我在源顺序中排在第一位,所以我显示为页面.</p>

<div data-role="page" id="home"><div data-role="header"><h1>主页</h1>

<div data-role="内容"><p>我是源顺序中的第二个,所以当页面加载时我是隐藏的.我只会看到是否有人点击了引用我的 ID 的链接.</p>

<div data-role="page" id="bar"><div data-role="header"><h1>条形</h1>

<div data-role="内容"><p>我是源顺序中的第二个,所以当页面加载时我是隐藏的.我只会看到是否有人点击了引用我的 ID 的链接.</p>

解决方案

示例

工作示例:http://jsfiddle.net/Gajotres/UfDaf/

使用的代码

这部分将阻止正常的页面加载.不要忘记,就像在我的示例中一样,mobileinit 必须jQuery Mobile 被初始化之前被初始化.

$(document).on("mobileinit",function() {$.mobile.autoInitializePage = false;});

这部分将开始手册页初始化:

$(document).ready(function() {window.location.hash = '家';$.mobile.initializePage();});

虽然我通常建议不要在这里使用文档就绪,但我们需要它来启动手动更改.

完整代码示例

如果 jsFiddle 关闭.

HTML:

<头><title>jQM Complex Demo</title><meta http-equiv='Content-Type' content='text/html;字符集=utf-8'/><元名称=视口"内容=宽度=设备宽度;初始规模=1.0;最大尺度=1.0;最小尺度=1.0;用户可扩展=否;目标密度Dpi=设备-dpi"/><link rel="样式表";href=http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css"/><script src=http://code.jquery.com/jquery-1.9.1.min.js"></script><脚本>$(document).on(mobileinit",function() {$.mobile.autoInitializePage = false;});<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"</script><身体><div 数据角色=页面"id="foo"><div data-role="header"><h1>Foo</h1>

<div data-role=内容"><p>我在源顺序中排在第一位,所以我显示为页面.</p>

<div 数据角色=页面"id=家"><div data-role="header"><h1>主页</h1>

<div data-role=内容"><p>我是源顺序中的第二个,所以当页面加载时我是隐藏的.我只会看到是否有人点击了引用我的 ID 的链接.</p>

<div 数据角色=页面"id=条"><div data-role="header"><h1>条形</h1>

<div data-role=内容"><p>我是源顺序中的第二个,所以当页面加载时我是隐藏的.我只会看到是否有人点击了引用我的 ID 的链接.</p>

Javascript:

$(document).ready(function() {window.location.hash = '家';$.mobile.initializePage();});

How can I show the second page as the default page in a jQuery mobile Multi-page template structure?

<body> 
<div data-role="page" id="foo">
    <div data-role="header">
        <h1>Foo</h1>
    </div>
    <div data-role="content">   
        <p>I'm first in the source order so I'm shown as the page.</p>      
    </div>
</div>
<div data-role="page" id="home">
    <div data-role="header">
        <h1>Home</h1>
    </div>
    <div data-role="content">   
        <p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my id is beeing clicked.</p>      
    </div>
</div>
<div data-role="page" id="bar">
    <div data-role="header">
        <h1>Bar</h1>
    </div>
    <div data-role="content">   
        <p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my id is beeing clicked.</p>      
    </div>
</div>
</body>

解决方案

Example

Working example: http://jsfiddle.net/Gajotres/UfDaf/

Code used

This part will prevent normal page load. Don't forget, like in my example mobileinit MUST be initialized before jQuery Mobile is initialized.

$(document).on("mobileinit",function() {
    $.mobile.autoInitializePage = false;
}); 

This part will start manual page initialization:

$(document).ready(function() {            
    window.location.hash = 'home';
    $.mobile.initializePage();
});

While I usually advise against of document ready usage here we need it to kick start the manual change.

Full code example

In case jsFiddle is down.

HTML :

<!DOCTYPE html>
<html>
    <head>
        <title>jQM Complex Demo</title>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
        <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script>
            $(document).on("mobileinit",function() {
                $.mobile.autoInitializePage = false;
            });        
        </script>
        <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>    
    </head>
    <body>
        <div data-role="page" id="foo">
            <div data-role="header">
                <h1>Foo</h1>
            </div>
            <div data-role="content">   
                <p>I'm first in the source order so I'm shown as the page.</p>      
            </div>
        </div>
        <div data-role="page" id="home">
            <div data-role="header">
                <h1>Home</h1>
            </div>
            <div data-role="content">   
                <p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my id is beeing clicked.</p>      
            </div>
        </div>
        <div data-role="page" id="bar">
            <div data-role="header">
                <h1>Bar</h1>
            </div>
            <div data-role="content">   
                <p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my id is beeing clicked.</p>      
            </div>
        </div>        
    </body>
</html>   

Javascript :

$(document).ready(function() {            
    window.location.hash = 'home';
    $.mobile.initializePage();
});

这篇关于如何在 jQuery mobile 多页模板结构中将第二页显示为默认页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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