I am new for jquery mobile. I got two pages which are page1.html and page2.html. page1 will navigate to page2 and inside page2 got a navbar.

Here is my code page1.html navigate to page2

  $.mobile.pageContainer.pagecontainer("change", "page2.html", {
    allowSamePageTransition: true,
    transition: 'none',
    showLoadMsg: false,
    reloadPage: false,
    changeHash: true

})

page2.html

  <!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>collapsible demo</title>
    <link rel="stylesheet" href="//code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
    <script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="//code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>
<body>

    <div data-role="page" id="page1">
        <div data-role="header">
            <h1>jQuery Mobile Example</h1>
        </div>
        <div data-role="content" class="ui-content">
            <div data-role="tabs">
                <div data-role="navbar">
                    <ul>
                        <li><a href="#fragment-1">One</a></li>
                        <li><a href="#fragment-2">Two</a></li>
                        <li><a href="#fragment-3">Three</a></li>
                    </ul>
                </div>
                <div id="fragment-1">
                    <p>This is the content of the tab 'One', with the id fragment-1.</p>
                </div>
                <div id="fragment-2">
                    <p>This is the content of the tab 'Two', with the id fragment-2.</p>
                </div>
                <div id="fragment-3">
                    <p>This is the content of the tab 'Three', with the id fragment-3.</p>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

It can be work if i run page2 individually. But problem come once i change page from page1 to page2. please dont reply me add rel="external" It may cause white screen issue once i using rel="external"

有帮助吗?

解决方案

This is a known jQuery Mobile 1.4 bug, it will be fixed in jQuery Mobile 1.4.3 version.

Read more about it here: https://github.com/jquery/jquery-mobile/issues/7169

There you will also find a workaround.

There's one other solution, it requires you to dynamically create tab widget, something like this:

$(document).on("pagecreate", "#p2", function () {
    var tabs = '<div data-role="tabs" id="tbPaymentMethod"><div data-role="navbar"><ul><li><a href="#tabCash">Tab 1</a></li><li><a href="#tabCcard">Tab 2</a></li><li><a href="#tabCheck">Tab 3</a></li></ul></div><div id="tabCash"><p>This is the content of the tabwith the id fragment-1.</p></div><div id="tabCcard"><p>This is the content of the tabwith the id fragment-2.</p></div><div id="tabCheck"><p>This is the content of the tabwith the id fragment-3.</p></div></div>';
    $("#p2 .ui-content").append(tabs).enhanceWithin();
});

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top