1***@qq.com
1***@qq.com
  • 发布:2016-08-22 10:15
  • 更新:2016-08-22 13:21
  • 阅读:2273

mui nav 页面相互跳转打开新页 不在h5+环境 怎么应用

分类:MUI

<!-- 主页面标题 -->
<nav class="mui-bar mui-bar-tab">
<a id="home" class="mui-tab-item" href="home.html">
<span class="mui-icon mui-icon-home"></span>
<span class="mui-tab-label">首页</span>
</a>
<a id="course" class="mui-tab-item mui-active" href="course.html">
<span class="mui-icon mui-icon-extra mui-icon-extra-xiaoshuo"></span>
<span class="mui-tab-label">课程中心</span>
</a>
<a id="shoppingcart" class="mui-tab-item" href="shoppingcart.html">
<span class="mui-icon mui-icon-extra mui-icon-extra-cart"></span>
<span class="mui-tab-label">购物车</span>
</a>
<a id="my" class="mui-tab-item" href="my.html">
<span class="mui-icon mui-icon-contact"></span>
<span class="mui-tab-label">我的</span>
</a>
</nav>

document.getElementById('home').addEventListener('tap', function() {  
                //打开首页页面  
                mui.openWindow({  
                    url:'home.html',  
                    id: 'home'  
                })  
                });  
document.getElementById('course').addEventListener('tap', function() {  
                //打开课程页面  
                mui.openWindow({  
                    url:'course.html',  
                    id: 'course'  
                })  
                });  
document.getElementById('shoppingcart').addEventListener('tap', function() {  
                //打开购物车页面  
                mui.openWindow({  
                    url:'shoppingcart',  
                    id: 'shoppingcart'  
                })  
                });

以上代码 怎么合并一个 把值传进去

2016-08-22 10:15 负责人:无 分享
已邀请:

最佳回复

赵梦欢

赵梦欢 - 专注前端,乐于分享!

1***@qq.com

1***@qq.com (作者)

照着你提供的文档说明做了一遍不管用打不开子页面 不知道为什么。。。

//设置默认打开首页显示的子页序号;  
            var Index = 0;  
            //把子页的路径写在数组里面  
            var subpages = ['home.html', 'course.html', 'course.html'];  
            //所有的plus-*方法写在mui.plusReady中或者后面。  
            mui.plusReady(function() {  
                //获取当前页面所属的Webview窗口对象  
                var self = plus.webview.currentWebview();  
                for(var i = 0; i < 3; i++) {  
                    //创建webview子页  
                    var sub = plus.webview.create(  
                        subpages[i], //子页url  
                        subpages[i], //子页id  
                        {  
                            top: '45px', //设置距离顶部的距离  
                            bottom: '50px' //设置距离底部的距离  
                        }  
                    );  
                    //如不是我们设置的默认的子页则隐藏,否则添加到窗口中  
                    if(i != Index) {  
                        sub.hide();  
                    }  
                    //将webview对象填充到窗口  
                    self.append(sub);  
                }  
            });  
    var createIframe = function (el, opt) {  
    var elContainer = document.querySelector(el);  
    var wrapper = document.querySelector(".mui-iframe-wrapper");  
    if(!wrapper){  
        // 创建wrapper 和 iframe  
        wrapper = document.createElement('div');  
        wrapper.className = 'mui-iframe-wrapper';  
        for(var i in opt.style){  
            wrapper.style[i] = opt.style[i];  
        }  
        var iframe = document.createElement('iframe');  
        iframe.src = opt.url;  
        iframe.id = opt.id || opt.url;  
        iframe.name = opt.id;  
        wrapper.appendChild(iframe);  
        elContainer.appendChild(wrapper);  
    }else{  
        var iframe = wrapper.querySelector('iframe');  
        iframe.src = opt.url;  
        iframe.id = opt.id || opt.url;  
        iframe.name = iframe.id;  
    }  
};  
            var activeTab = subpages[Index],title=document.querySelector(".mui-title");  
mui('.mui-bar-tab').on('tap', 'a', function(e) {  
    // 获取目标子页的id  
    var targetTab = this.getAttribute('href');  
    if (targetTab == activeTab) {  
        return;  
    }          
    // 更换标题  
    title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;      
    // 子页内容切换  
    if(mui.os.plus){  
        // 显示目标webview  
        plus.webview.show(targetTab);  
        // 隐藏当前webview  
        plus.webview.hide(activeTab);  
        // 更改当前活跃的选项卡  
        activeTab = targetTab;  
    }else{  
        // 创建iframe代替子页面  
        createIframe('.mui-content',{  
            url: targetTab,  
            style: {  
                top: '45px',//设置距离顶部的距离  
                bottom: '50px'//设置距离底部的距离  
            }  
        });  
    }  
})
  • 赵梦欢

    不多说,这种东西没啥好说的,思路都已经写得清清楚楚,直接上演示demo:https://rawgit.com/zhaomenghuan/mui-demo/master/example/tabbar-with-iframe/tab-webview-main.html

    2016-08-22 13:48

  • 1***@qq.com (作者)

    解决了 谢谢 是我自己马虎了 路径错了

    2016-08-22 13:51

  • 1***@qq.com (作者)

    回复 赵梦欢: 非常到位 万分感谢

    2016-08-22 13:56

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