2013-04-27 67 views
0

我正在使用jQuery mobile multipage template,我想以编程方式打开第二页。下面是我的示例HTML:jQuery Mobile:使用changePage方法时出现“Type Error”

<!DOCTYPE html> 
<html> 
<head> 
<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 src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script> 
<meta charset="utf-8" /> 

</head> 
<body> 
    <!--===========This is the first page==========--> 
    <div data-role="page" id="page1"> 
     <div data-role="header" data-theme="e"> 
      <h1>Dialog</h1> 
     </div> 
     <div data-role="content" data-theme="a">  
      <h1>This is page One</h1> 
     </div> 
     <div data-role="footer"> 
      <h4>Page Footer</h4> 
     </div> 
    </div> 

    <!--========================================================--> 

    <!--===========This is the second page==========--> 
    <div data-role="page" id="page2"> 
     <div data-role="header" data-theme="e"> 
      <h1>Dialog</h1> 
     </div> 
     <div data-role="content" data-theme="a">  
      <h1>This is page Two</h1> 
      < 
     </div> 
     <div data-role="footer"> 
      <h4>Page Footer</h4> 
     </div> 
    </div> 
    <script> 
     jQuery.mobile.changePage($("#page2")); 
    </script> 
</body> 
</html> 

一切似乎都OK,但是当我打开这个网页,我得到的萤火以下错误:

TypeError: u is undefined

我明白任何评论

+0

你想打开它吗?检查这个答案http://stackoverflow.com/questions/16253300/removeclass-working-on-jsfiddle-but-not-in-the-browser/16253556#16253556 – Omar 2013-04-27 20:08:04

回答

2

括在jQuery代码document.ready()处理程序:

$(document).ready(function() { 
    jQuery.mobile.changePage($("#page2")); 
}); 
+0

Tnx很多,我忘了:D ...它现在像一种魅力。 – 2013-04-27 17:24:38

+0

'.ready()'不推荐用于jQuery Mobile。 – Omar 2013-04-27 20:00:33