0

我有一个带有两页的简单 index.html ......

<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <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.10.0.min.js"></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="page1">
  <div></div>
</div>

<div data-role="page" id="page2">
  <div></div>
</div>
</body>
</html>

Page1 有一个按钮。当用户点击它时,我调用 js 函数。

function openPage2() {
}

此函数应加载第 2 页。怎么做 ?

我试过了

$.mobile.changePage("page2.html");

但它不工作......我做错了什么?

4

1 回答 1

2

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

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.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>    
</head>
<body>
    <div data-role="page" id="page1">
        <div data-theme="a" data-role="header">
            <h3>
                First Page
            </h3>
        </div>

        <div data-role="content">
            <a href="" data-role="button" id="next-page">Next</a>
        </div>

        <div data-theme="a" data-role="footer" data-position="fixed">

        </div>
    </div> 
    <div data-role="page" id="page2">
        <div data-theme="a" data-role="header">
            <h3>
                Second Page
            </h3>
            <a href="#index" class="ui-btn-left">Back</a>
        </div>

        <div data-role="content">

        </div>

        <div data-theme="a" data-role="footer" data-position="fixed">

        </div>
    </div>    
</body>
</html>   

Javascript:

$(document).on('pagebeforeshow', '#page1', function(){       
    $(document).on('click', '#next-page', function(){     
        $.mobile.changePage("#page2");
    });        
});
于 2013-06-04T14:27:11.457 回答