sunlawa
sunlawa
  • 发布:2015-01-07 01:22
  • 更新:2015-01-07 10:48
  • 阅读:3927

mui.back没有反应

分类:MUI
<!DOCTYPE html>  
<html>  
    <head>  
        <meta charset="utf-8">  
        <title>Hello Mui</title>  
        <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">  
        <meta name="apple-mobile-web-app-capable" content="yes">  
        <meta name="apple-mobile-web-app-status-bar-style" content="black">  

        <link rel="stylesheet" href="css/mui.min.css">  
        <script src="js/mui.min.js"></script>  
        <script src="js/app.js"></script>  
        <style>  
            html,body {  
                background-color: #efeff4;  
            }  
        </style>  
    </head>  

    <body>  
        <header class="mui-bar mui-bar-nav">  
            <h1 id="title" class="mui-title">首页</h1>  
        </header>  

        <nav class="mui-bar mui-bar-tab">  
            <a id="defaultTab" class="mui-tab-item mui-active" href="www/Individual-Index.html">  
                <span class="mui-icon mui-icon-home"></span>  
                <span class="mui-tab-label">首页</span>  
            </a>  
            <a class="mui-tab-item" href="www/Individual-Index.html">  
                <span class="mui-icon mui-icon-map"></span>  
                <span class="mui-tab-label">页面1</span>  
            </a>  
            <a class="mui-tab-item" href="www/Individual-Index.html">  
                <span class="mui-icon mui-icon-compose"></span>  
                <span class="mui-tab-label">页面2</span>  
            </a>  
            <a class="mui-tab-item" href="www/Individual-Index.html">  
                <span class="mui-icon mui-icon-pengyouquan"></span>  
                <span class="mui-tab-label">页面3</span>  
            </a>  
            <a class="mui-tab-item" href="www/Individual-Center.html">  
                <span class="mui-icon mui-icon-contact"></span>  
                <span class="mui-tab-label">页面4</span>  
            </a>  
        </nav>  
        <script type="text/javascript" charset="utf-8">  
            var subpages = ['www/Individual-Index.html','www/Individual-Index.html','www/Individual-Index.html','www/Individual-Index.html','www/Individual-Center.html'];  
            var subpage_style = {  
                top: '46px',  
                bottom: '50px'  
            };  

            //创建子页面,首个选项卡页面显示,其它均隐藏;  
            mui.plusReady(function(){  
                var self = plus.webview.currentWebview();  
                for(var i=0;i<5;i++){  
                    var sub = plus.webview.create(subpages[i],subpages[i],subpage_style);  
                    if(i>0){  
                        sub.hide();  
                    }  
                    self.append(sub);  
                }  
            });  

            //当前激活选项  
            var activeTab = subpages[0];  
            var title = document.getElementById("title");  
            //选项卡点击事件  
            mui('.mui-bar-tab').on('tap', 'a', function(e) {  
                var targetTab = this.getAttribute('href');  
                if (targetTab == activeTab) {  
                    return;  
                }  
                //更换标题  
                title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;  
                //显示目标选项卡  
                plus.webview.show(targetTab);  
                //隐藏当前;  
                plus.webview.hide(activeTab);  
                //更改当前活跃的选项卡  
                activeTab = targetTab;  
            });  

            //首页返回键处理  
            //处理逻辑:1秒内,连续两次按返回键,则退出应用;  
            mui.init({  
                swipeBack: false,  
                statusBarBackground:'#f7f7f7'  
            });  
            var first = null;  
            mui.back = function() {  
                //首次按键,提示‘再按一次退出应用’  
                if (!first) {  
                    first = new Date().getTime();  
                    mui.toast('再按一次退出应用');  
                    setTimeout(function() {  
                        first = null;  
                    }, 1000);  
                } else {  
                    if (new Date().getTime() - first < 1000) {  
                        plus.runtime.quit();  
                    }  
                }  
            };  
        </script>  
    </body>  
</html>
2015-01-07 01:22 负责人:无 分享
已邀请:
DCloud_UNI_CHB

DCloud_UNI_CHB

看一下mui版本及HBuilder版本

  • sunlawa (作者)

    Mui v0.9.0 & HBuilder 5.0.0.201501040824

    2015-01-07 10:11

  • DCloud_UNI_CHB

    升级到mui 1.0版本吧;直接升级的话,应该不需要改代码,在老版本mui上的话,需要取消子页面的back按键监听;

    2015-01-07 10:38

sunlawa

sunlawa (作者)

Mui v0.9.0 & HBuilder 5.0.0.201501040824

bxh201

bxh201

你的app.js 有没有重写mui.back?

  • sunlawa (作者)

    有重写,但是我注释掉好像也不行

    2015-01-07 10:26

sunlawa

sunlawa (作者)

我将取消app.js引用,还是不行,如果我在mui.plusReady中没有创建子页面就正常!

sunlawa

sunlawa (作者)

将页面的
//首页返回键处理
//处理逻辑:1秒内,连续两次按返回键,则退出应用;
mui.init({
swipeBack: false,
statusBarBackground:'#f7f7f7'
});
var first = null;
mui.back = function() {
//首次按键,提示‘再按一次退出应用’
if (!first) {
first = new Date().getTime();
mui.toast('再按一次退出应用');
setTimeout(function() {
first = null;
}, 1000);
} else {
if (new Date().getTime() - first < 1000) {
plus.runtime.quit();
}
}
};
放在app.js中

(function($) {
//全局配置(通常所有页面引用该配置,特殊页面使用mui.init({})来覆盖全局配置)
$.initGlobal({
swipeBack:false,
statusBarBackground:'#f7f7f7'
});
var back = $.back;
var first = null;
//首页返回键处理
//处理逻辑:1秒内,连续两次按返回键,则退出应用;

$.back = function() {  
    var current = plus.webview.currentWebview();  
    if (!first) {  
        first = new Date().getTime();  
        mui.toast('再按一次退出应用');  
        setTimeout(function() {  
            first = null;  
        }, 1000);  
    } else {  
        if (new Date().getTime() - first < 1000) {  
            plus.runtime.quit();  
        }  
    }  
}  

})(mui);
这样可以了!

该问题目前已经被锁定, 无法添加新回复