8

jQueryモバイルマルチページテンプレート構造で、2番目のページをデフォルトページとして表示するにはどうすればよいですか?

<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>
4

2 に答える 2

14

作業例: http://jsfiddle.net/Gajotres/UfDaf/

使用したコード

この部分は、通常のページの読み込みを妨げます。私の例のように、 mobileinitを初期化する前に初期化する必要があることを忘れないでくださいjQuery Mobile

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

この部分はマニュアルページの初期化を開始します:

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

私は通常、ここでドキュメントの準備ができている使用に反対することをお勧めしますが、手動の変更を開始するにはそれが必要です.

完全なコード例

ダウンした場合jsFiddle

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();
});
于 2013-05-24T11:26:04.693 に答える
0

この質問は少し古いことは知っていますが、簡単な解決策に出くわしました:

window.location.href = "_dash.html#page-two";

または、別のページからナビゲートしている場合は、次のように 2 番目のページにドロップするリンクを作成できます。

<a href="_dash.html#page-two">link to second page</a>

URL の末尾に 2 番目のページのページ ID を追加するだけです。

于 2017-06-02T14:03:02.267 に答える