1

我有两个页面,我计划使用 JQM 移动框架导航,我计划多个页面,为了让我的代码整洁,我决定将多个页面放在不同的 html 文件中。在导航到下一个屏幕页面刷新页面 CSS 未加载。

 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Page 1</title>
<link rel="stylesheet"
    href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<script
    src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<script type="text/javascript">
$(document).swipeleft(function() {
    $.mobile.changePage("page2.html");
});

</script>
</head>
<body>
    <div data-role="page" id="page1" data-dom-cache="true">
    <div data-role="header"></div>
        <div data-role="content">
            <div data-role="collapsible-set" data-theme="c" data-content-theme="d">
                <div data-role="collapsible">
                    <h3>Section 1</h3>
                    <p><a href="page2.html" data-transition="slide" >I'm the collapsible content for section 1</a></p>
                </div>
                <div data-role="collapsible">
                    <h3>Section 2</h3>
                    <p>I'm the collapsible content for section 2</p>
                </div>
                <div data-role="collapsible">
                    <h3>Section 3</h3>
                    <p>I'm the collapsible content for section 3</p>
                </div>
            </div>
        </div>  
        <div data-role="footer"></div> 
    </div>

</body>
</html>

第 2 页:我有以下代码

<div data-role="page" id="page2" data-dom-cache="true">
<div data-role="header"></div>
    <div data-role="content">
        <div data-role="collapsible-set" data-theme="c" data-content-theme="d">
            <div data-role="collapsible">
                <h3>Page 2</h3>
                <p>
                    <a href="page3.html" data-transition="slide">I'm the
                        collapsible content for section 1</a>
                </p>
            </div>
            <div data-role="collapsible">
                <h3>Section 2</h3>
                <p>I'm the collapsible content for section 2</p>
            </div>
            <div data-role="collapsible">
                <h3>Section 3</h3>
                <p>I'm the collapsible content for section 3</p>
            </div>
        </div>
    </div>
    <div data-role="footer"></div>
</div>

导航发生,但是当我刷新页面时,css 被删除。如何拥有多个页面并在屏幕之间导航。

4

2 回答 2

2

将您的page1.html更改为以下

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<title>Page 1</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
</head>
<body>
    <div data-role="page" id="page1" data-dom-cache="true">
    <div data-role="header"></div>
        <div data-role="content">
            <div data-role="collapsible-set" data-theme="c" data-content-theme="d">
                <div data-role="collapsible">
                    <h3>Section 1</h3>
                    <p><a href="page2.html" data-transition="slide" >I'm the collapsible content for section 1</a></p>
                </div>
                <div data-role="collapsible">
                    <h3>Section 2</h3>
                    <p>I'm the collapsible content for section 2</p>
                </div>
                <div data-role="collapsible">
                    <h3>Section 3</h3>
                    <p>I'm the collapsible content for section 3</p>
                </div>
            </div>
        </div>  
        <div data-role="footer"></div> 
    </div>
<script type="text/javascript">
$('#page1').on('pageshow',function(event){
    $("#page1").swiperight(function () {
        $.mobile.changePage("page2.html");
    });

});
</script>
</body>
</html>

并更改您的page2.html如下

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<title>Page 1</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
</head>
<body>
    <div data-role="page" id="page2" data-dom-cache="true">
        <div data-role="header"></div>
            <div data-role="content">
                <div data-role="collapsible-set" data-theme="c" data-content-theme="d">
                    <div data-role="collapsible">
                        <h3>Page 2</h3>
                        <p>
                            <a href="page3.html" data-transition="slide">I'm the
                                collapsible content for section 1</a>
                        </p>
                    </div>
                    <div data-role="collapsible">
                        <h3>Section 2</h3>
                        <p>I'm the collapsible content for section 2</p>
                    </div>
                    <div data-role="collapsible">
                        <h3>Section 3</h3>
                        <p>I'm the collapsible content for section 3</p>
                    </div>
                </div>
            </div>
            <div data-role="footer"></div>
        </div>
<script type="text/javascript">
$('#page2').on('pageshow',function(event){
    alert('page2 loaded');
});
</script>
</body>
</html>

它现在应该可以工作了。请告诉我会发生什么。我把脚本包在里面$('#page2').on('pageshow',function(event){});。这是我所做的唯一改变。

于 2013-03-11T08:33:20.437 回答
1

i was referring to http://m.stanford.edu/#events which used older version JQM

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1 jquery.mobile1.0a4.1.min.css" /> 
<script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>

and in latest version ie

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>

The above issue is done for the latest version by

$(document).on("mobileinit", function () {
    $.mobile.pushStateEnabled = false; 
});
于 2013-03-12T12:03:07.423 回答