JQuery Mobile 学习笔记2-4:changePage()方法跳转页面

来源:互联网 发布:移动网络下载不了电影 编辑:程序博客网 时间:2024/05/29 10:56

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Murphy_JQueryMobile的changePage()方法跳转页面</title>

<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.8.2.min.js"></script>

<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

<script type="text/javascript">

$(function(){

    $.mobile.changePage('about.html',{

        transition:'slideup'

    });

});

</script>

</head>


<body>

<section data-role="page" id="el">

<header data-role="header"><h1>跳转页面</h1></header>

    <div data-role="content">

    <p>页面正在跳转中......</p>

    </div>

    <footer data-role="footer"><h4>&copy;2013 imurphy.lofter.com</h4></footer>

</section>

</div>

</body>

</html>

about.html

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Murphy_JQueryMobile的changePage()方法跳转页面-about.html</title>

<meta name="viewport" content="width=device-width,initial-scale=1"/>

</head>


<body>

<section data-role="page" id="el" data-add-back-btn="true">

<header data-role="header"><h1>关于Murphy</h1></header>

    <div data-role="content">

    <p>页面直接从当前页跳转到“about.html”页面中</p>

    </div>

    <footer data-role="footer"><h4>&copy;2013 imurphy.lofter.com</h4></footer>

</section>

</div>

</body>

</html>

changePage()方法

此方法除了可以跳转页面外,还能带数据传递给跳转的目标页,如下面代码所示

.post('../visitor/checkRegister.do',{
  regemail:email,
   }, function(data) {
    //代表邮箱已注册
       if(data.data.regstatus=="true"){
       //$.mobile.changePage("../front/Exhibition_mobile_login.html",{ transition: "pop" });
       $.mobile.changePage('../front/Exhibition_mobile_login.html',{
       data:"exhibition_id="+exhibition_id,    
   },
   'pop',false,true
 );
   return false;
      } 

表示通过ajax实现了visitor/checkRegister.do'跳转,如果成功的话就跳转到

"pop"表示跳转时页面的效果

第一个"fasle"值表示跳转·时的方向,如果为“true“表示反方向跳转,默认值为"fasle"

第二个"fasle"表示完成跳转后是否更新历史记录,默认为"true",表示更新

说明:如果指定跳转的目标页不存在或传递的数据格式不正确时,都会在当前页面出现一个错误提示框,几秒之后自动消失,不影响当前页面的内容显示


注:当作这个demo时遇到一个问题,就是在跳转的时候出现了”error loading page“,那是jquery mobile不支持file://,也就是本地文件,所以要将其上传到服务器上运行

0 0