mui:返回上级页面时的参数传递

在APP的开发过程中我们经常用到在下级页面填写数据,填完后返回上级页面提交的情况。比如在微信中我们修改了微信昵称之后,需要在返回到个人信息的界面显示出来。下面我们就以实例来为大家分享MUI点击返回按钮时的参数传递。

演示效果:(从A页面访问B页面,在B页面点击返回按钮把B页面填写的参数传递给A页面)

mui返回按钮参数传递

A页面源代码:

  1. <!DOCTYPE html>
  2.     <html>
  3.         <head>
  4.             <meta charset="UTF-8">
  5.             <title></title>
  6.             <link href="../../css/mui.min.css" rel="stylesheet" />
  7.             <script src="../../../js/mui.min.js"></script>
  8.             <script src="../../../js/jquery.js"></script>
  9.             <script>
  10.                     mui.init()
  11.                     function plusReady(){
  12.                          mui("body").on("tap",".jump",function(){
  13.                             mui.openWindow({
  14.                                 url:"b.html",
  15.                                 id:"b"
  16.                             })
  17.                          })
  18.                     }
  19.                     if(window.plus){
  20.                         plusReady();
  21.                     }else{
  22.                         document.addEventListener("plusready",plusReady,false);
  23.                     }
  24.                     //返回回来要执行的方法   
  25.                     function fun1(e){
  26.                         var val=e.detail.inputVal
  27.                         $(".a1 font").html(val)
  28.                     }
  29.                     //自定义窗体事件  doit 要和b页面定义的 事件名称一致   
  30.                     window.addEventListener('doit',fun1);
  31.             </script>
  32.         </head>
  33.         <body>
  34.             <a href="javascript:void(0);" class="jump">跳转到B页面</a>
  35.             <div class="a1">返回回来的值是------<font style=" font-size:20px;color:#2AC845"></font></div>
  36.             <div style=" font-size:50px ; text-align: center; display: block; margin: 50px 0 0 0;">a.html页面</div>
  37.         </body>
  38.     </html>

B页面源代码:

  1. <!DOCTYPE html>
  2.     <html>
  3.         <head>
  4.             <meta charset="UTF-8">
  5.             <title></title>
  6.             <link href="../../css/mui.min.css" rel="stylesheet" />
  7.             <script src="../../../js/mui.min.js"></script>
  8.             <script src="../../../js/jquery.js"></script>
  9.             <script>
  10.                     mui.init()
  11.                     if(window.plus){
  12.                         plusReady();
  13.                     }else{
  14.                         document.addEventListener("plusready",plusReady,false);
  15.                     }
  16.                     function plusReady(){
  17.                          mui("body").on("tap",".jump",function(){
  18.                             var view=plus.webview.getWebviewById("HBuilder");//注意  HBuilder是上个页面的ID你自己要替换掉                                  
  19.                             mui.fire(view,'doit',{
  20.                                 inputVal:$("#text").val()
  21.                             });
  22.                             mui.back()
  23.                          })
  24.                     }
  25.             </script>
  26.         </head>
  27.         <body>
  28.             <input type="text" id="text">
  29.             <a href="javascript:void(0)" class="jump">返回</a>
  30.             <div style=" font-size:50px ; text-align: center; display: block; margin: 50px 0 0 0;">b.html页面</div>
  31.         </body>
  32.     </html>

更多关于mui页面参数传递的问题也可参考MUI官方文档:http://ask.dcloud.net.cn/article/63 敬请关注菠菜园其他精彩文章。

你想把广告放到这里吗?

发表评论

您必须 登录 才能发表留言!