mui mui.fire()自定义事件页面间传值
mui mui.fire()自定义事件页面间传值
wenxingjun 发表于5个月前
mui mui.fire()自定义事件页面间传值
  • 发表于 5个月前
  • 阅读 22
  • 收藏 1
  • 点赞 0
  • 评论 0

腾讯云 新注册用户 域名抢购1元起>>>   

方法1.给预加载页面传值

first.html:

<!DOCTYPE html>  
<html>  
  
    <head>  
        <meta charset="utf-8">  
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />  
        <title>mui自定义事件页面间传值</title>  
        <script src="js/mui.min.js"></script>  
        <link href="css/mui.min.css" rel="stylesheet" />  
        <script type="text/javascript" charset="utf-8">  
            mui.init({  
                preloadPages: [{//预加载目标页面  
                    'url': 'second.html',  
                    'id': 'second.html'  
                }]  
            });  
            window.onload = function() {  
                var Page = null;  
                document.getElementById("a1").addEventListener('tap', function() {  
                    if (!Page) {  
                        Page = plus.webview.getWebviewById('second.html');  
                    }  
                    mui.fire(Page, 'show', {  
                        id: 'id1',     //传往second.html的值  
                        name: 'name2'  //传往second.html的值  
                    });  
                    mui.openWindow({ //目标页面  
                        id: 'second.html',  
                    });  
                });  
            }  
        </script>  
    </head>  
    <body>  
        <a id="a1">跳转</a>  
    </body>  
  
</html>  

second.html:

<!DOCTYPE html>  
<html>  
    <head>  
        <meta charset="utf-8">  
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />  
        <title>mui自定义事件页面间传值</title>  
        <script src="js/mui.min.js"></script>  
        <link href="css/mui.min.css" rel="stylesheet" />  
        <script type="text/javascript" charset="utf-8">  
             //添加newId自定义事件监听  
                window.addEventListener('show', function(event) {  
                    //获得事件参数  
                    var id = event.detail.id;  
                    var name = event.detail.name;  
                    alert(id);  
                    alert(name);  
                })  
        </script>  
    </head>  
    <body>  
    </body>  
</html>  

方法2.  页面初始化时,通过扩展参数传值

first.html:

<!DOCTYPE html>  
<html>  
    <head>  
        <meta charset="utf-8">  
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />  
        <title>mui自定义事件页面间传值</title>  
        <script src="js/mui.min.js"></script>  
        <link href="css/mui.min.css" rel="stylesheet" />  
        <script type="text/javascript" charset="utf-8">  
            mui.init();  
            var param = { 
                userId: 'userId',  
                userName: 'userName'  
            };  
  
            function thePage() {  
                mui.openWindow({
                    url: 'second.html',  
                    id: 'second.html',  
                    extras: param  
                });  
            }  
        </script>  
    </head>  
    <body>  
        <a onclick="thePage()">新页面</a>  
    </body>  
</html>  

second.html:

<!DOCTYPE html>  
<html>  
    <head>  
        <meta charset="utf-8">  
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />  
        <title>mui自定义事件页面间传值</title>  
        <script src="js/mui.min.js"></script>  
        <link href="css/mui.min.css" rel="stylesheet" />  
        <script type="text/javascript" charset="utf-8">  
            mui.plusReady(function() {  
                var self = plus.webview.currentWebview();  
                alert(self.userId);  
            });  
        </script>  
    </head>  
    <body>  
    </body>  
</html>  

 

标签: mui
共有 人打赏支持
粉丝 0
博文 21
码字总数 6797
×
wenxingjun
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: