5***@qq.com
5***@qq.com
  • 发布:2017-11-03 16:04
  • 更新:2017-11-03 17:14
  • 阅读:1483

安卓环境用webview打开一个可下拉刷新,下拉加载的页面报错的问题

分类:HTML5+

开发webapp的时候发现了一个问题,有一个页面,在安卓环境下打开一个可以上拉加载,下拉刷新的页面的时候会报错, iphone环境正常, 请大神帮我看一下是什么原因。谢谢

附件是精简后压缩的项目,解压后可Hbuilder打开,
代码:
A页面主要代码

<body>  
    <div id="loadingdiv" style="display:block;">  
        <div class="loading-block show">                          
           <span class="mui-spinner"></span>                   
        </div>  
    </div>  
    <div class="mui-content mui-row mui-fullscreen">  
        <div class="" style="width: 25%;float:left">  
            <div id="segmentedControls" class="mui-segmented-control mui-segmented-control-inverted mui-segmented-control-vertical">  
            </div>  
        </div>  
        <div id="segmentedControlContents" style="width:100%;height: 100%;">  
            <!--<div id="item1" class="mui-control-content mui-active">  
            </div>-->  
        </div>  
    </div>  
    <script src="js/mui.min.js"></script>  
    <script src="js/jquery-2.1.4.min.js"></script>  
    <script>  
        var mask=mui.createMask();//遮罩层  
        mui.init({  
            swipeBack: false //启用右滑关闭功能  

        });  
        mask.show();  
        var url = site + "Cate/index";  
        params = {};  
        $.post(url, params, function(data) {  
            var controls = document.getElementById("segmentedControls");  
            var html = [];  
            var first = data.first; //所有一级分类  
            var i = 0,  
                j = 1,  
                m = first.length, //左侧选项卡数量+1  
                n = 21; //每个选项卡列表数量+1  
            for(; i < m; i++) {  
                if(i == 0)  
                    right(first[i].id);  
                html.push('<a class="mui-control-item" href="#content" onclick="right(' + first[i]['id'] + ')">' + first[i]['name'] + '</a>');  
            }  
            controls.innerHTML = html.join('');  

            //默认选中第一个  
            controls.querySelector('.mui-control-item').classList.add('mui-active');  
            jQuery('#loadingdiv').hide();  
            mask.close();  
        });  

        function right(id) {  
            url = site + "Cate/right";  
            params = {  
                "id": id  
            };  
            $.post(url, params, function(data) {  
                cates = data.cates;  
                var contents = document.getElementById("segmentedControlContents");  
                html = [];  
                html.push('<div class="mui-table-view-cell" style="background:#fff;">' + data.title + '</div>');  
                html.push('<div id="content1" class="mui-control-content" style="background:#fff;"><ul class="mui-table-view">');  
                $.each(cates, function(k, v) {  
                    if(v.main_pic)  
                        var path = src_path + v.main_pic;  
                    else  
                        var path = "images/shop.png";  
                    html.push('<li class="color" data-url="productlist.html?id=' + v.id + '"><a><img src="' + path + '"></br>' + v.name + '</a></li>');  
                })  
                html.push('</ul></div>');  
                contents.innerHTML = html.join('');  
                contents.querySelector('.mui-control-content').classList.add('mui-active');  
            });  
            jQuery('#loadingdiv').hide();  
            mask.close();  
        }  
    </script>  
    <script>  
        $('body').on('tap','li',function(){  
            var tiaozhuan = $(this).data('url');  
            mui.openWindow(tiaozhuan,tiaozhuan);  
        });  
    </script>  
</body>

被打开页面b页面主要代码

<body>  
    <header class="mui-bar mui-bar-nav ">  
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>  
                <input type="search" class="mui-input-clear search" placeholder="" >  
            <button type="button" class="mui-btn"><span class="wai"></span></button>  
    </header>  
    <!--下拉刷新容器-->  
    <div id="pullrefresh" class="mui-content mui-scroll-wrapper">  
        <div class="mui-scroll">  
            <ul class="mui-table-view mui-grid-view" >    

            </ul>  
        </div>  
    </div>  
    <script type="text/javascript" src="js/jquery-2.1.4.min.js" ></script>  
    <script src="js/mui.min.js"></script>  
    <script>  

        var id=GetQueryString('id');          
        mui.init({  
            pullRefresh: {  
                container: '#pullrefresh',  
                down: {  
                    callback: pulldownRefresh,  
                },  
                up: {  
                    contentrefresh: '正在加载...',  
                    callback: pullupRefresh,  
                    auto: true,  
                    contentnomore:'没有更多数据了',//可选,请求完毕若没有更多数据时显示的提醒内容;  
                }  
            }  
        });  
        /**  
         * 下拉刷新具体业务实现  
         */  
        function pulldownRefresh() {  
                var table = document.body.querySelector('.mui-table-view');  
                var cells = document.body.querySelectorAll('.mui-table-view-cell');  
                var params = {};  
                params.p = cells.length?cells.length:0;  
                params.id = id;  
                var url = site+"Interface/getRefresh";  
                $(table).html("");  
                $.post(url, params, function(d){  
                            $.each(d.list, function(i,val){  
                                var fragment = document.createDocumentFragment();  
                                var html = '<a href="des.html?id='+val.id+'"><img class="mui-media-object" src="' + src_path + val.main_pic+'" src="./images/60x60.gif"><div class="mui-media-body">'+val.title+'</div><div class="goods_info"> <span class="price_info">¥'+val.discount_price+'</span><div class="goods_info"></div></div></a>';  
                                li = document.createElement('li');  
                                li.className = 'mui-table-view-cell mui-media mui-col-xs-6';  
                                li.innerHTML = html;  
                                fragment.appendChild(li);  
                                table.appendChild(fragment);  
                            });  

                },'json');  

                mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed  
        }  
        var count = 0;  
        /**  
         * 上拉加载具体业务实现  
         */  
        var title=false;  
        function pullupRefresh() {  
            var table = document.body.querySelector('.mui-table-view');  
            var cells = document.body.querySelectorAll('.mui-table-view-cell');  
            var params = {};  
            if(!title){  
                params.title=false;  
            }  
            params.p = cells.length?cells.length:0;  
            params.id = id;  
            var url = site+"Interface/getList";  
            $.post(url, params, function(d){  
                if(d.title){  
                    $(".wai").html(d.title+'<span class="mui-icon mui-icon-closeempty"></span>');  
                    title=true;  
                }  
                if(d.list != ""){  
                    $.each(d.list, function(i,val){  
                        var fragment = document.createDocumentFragment();  
                        var html = '<a href="des.html?id='+val.id+'"><img class="mui-media-object" src="' + src_path + val.main_pic+'" src="./images/60x60.gif"><div class="mui-media-body">'+val.title+'</div><div class="goods_info"> <span class="price_info">¥'+val.discount_price+'</span><div class="goods_info"></div></div></a>';  
                        li = document.createElement('li');  
                        li.className = 'mui-table-view-cell mui-media mui-col-xs-6';  
                        li.innerHTML = html;  
                        fragment.appendChild(li);  
                        table.appendChild(fragment);  
                    });  
                    mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);  
                }else{  
                    mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);  
                }  

            },'json');  
        }  
//      mui('#pullrefresh').on('tap','a',function(){  
//          document.location.href=this.href;  
//      });  
    </script>  
    <!--<script>  
        mui.plusReady(function(){  
            plus.nativeUI.closeWaiting();//这里监听页面是否加载完毕,完成后关闭等待框  
        })   
    </script>-->  
</body>  
2017-11-03 16:04 负责人:无 分享
已邀请:
5***@qq.com

5***@qq.com (作者) - 这家伙很懒,什么都没有留下~

不好意思了,最后发现是因为通过url, get传值报错的。 现在直接打开页面,然后值通过localStorage获取,然后就成功了。 尝试了通过openwebview传值,但是接收都是undefined,也不知道为什么。
比较急, 先用这个localStorage.getItem(),获取吧。

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