如何使用jQuery Mobile访问另一个页面?

时间:2010-11-13 15:06:25

标签: jquery html5

这看起来似乎是一个愚蠢的问题,但我似乎无法让jQuery加载另一个页面 - 当我包含一个链接时:

<a href="test.html" data-pop >Go to the test page</a> 

地址(假设我们来自index.html)只是获取了#test.html,这意味着我的地址结尾看起来像这样:

html/index.html#test.html

我的问题是,如何让它加载另一页?这是我的源代码:

<!DOCTYPE html> 
<html> 
    <head>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css" />
        <script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js"</script>

         <title>Test</title>
     </head>
     <body>
         <div data-role="page"> 
             <div data-role="header"></div> 
             <div data-role="content">
                 <p>This is a test</p>
                 <a href="test.html" data-pop >Go to the test page</a> 
             </div> 
             <div data-role="footer"></div> 
         </div> 
     </body>
 </html>

1 个答案:

答案 0 :(得分:3)

您的答案记录在案here。这个脚本包含在jquery和jquery mobile之间:

$(document).bind("mobileinit", function() {
  $.mobile.ajaxLinksEnabled = false;
});

请记住,它不适用于jquery mobile 1.0a1,但它适用于1.0a2。

所以整个index.html看起来像这样:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css" />
        <script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
        <script type="text/javascript">
            $(document).bind("mobileinit", function() {
              $.mobile.ajaxLinksEnabled = false;
            });
        </script>
        <script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>

        <title>Test</title>
    </head>
    <body>
        <div data-role="page">
            <div data-role="header"></div>
            <div data-role="content">
                <p>This is a test</p>
                <a href="test.html" data-pop >Go to the test page</a>
            </div>
            <div data-role="footer"></div>
        </div>
    </body>
</html>