1. 程式人生 > >mui.plusReady()不執行?mui傳參

mui.plusReady()不執行?mui傳參

需求:要在A介面中的卡頭(頭佈局)和卡位(底部tab)中載入webView呈現內容,在webView介面中獲取A介面頭佈局的title id和一個圖片id :
程式碼如下:
A介面中卡頭,卡頭佈局(頭佈局)的程式碼:

mui.init({
swipeBack: false,
statusBarBackground: '#82D1C5',
gestureConfig: {
tap: true,
},
subpages: [{
id: 'list.html',
url: 'list.html',
styles: {
top: '45px',
bottom: '50px',
bounce: 'vertical'
}, extras:{ divimg:'footer_left_div_id', title:'header_title_span' }//額外擴充套件引數 }] });

//在載入的webView介面中獲取2個相應的id:

<script type="text/javascript">
        /*dom準備就緒後,呼叫此事件*/

        function plusReady(){
            mui.plusReady(function(){
                var url=plus.webview.currentWebview().getURL();
                console.log("獲取當前頁面webView URL:=="
+url); //獲取模板介面中傳遞的引數 var self = plus.webview.currentWebview(); var divimg = self.divimg; var title = self.title; //持久化儲存 localStorage.setItem("current_page_url",url); localStorage.setItem("divimg"
,divimg); localStorage.setItem("title",title); console.log("傳遞過來的div img id:=="+divimg); console.log("傳遞過來的title id:=="+title); }); } if(window.plus){ plusReady(); console.log("window.plus"); }else{ document.addEventListener("plusready",plusReady,false); console.log("plusReady"); }
</script>

列印結果如下:

 plusReady at list.html:179
 獲取當前頁面webView URL:==file:///storage/emulated/0/Android/data/io.dcloud.HBuilder/.HBuilder/apps/HBuilder/www/list.html at list.html:157
 傳遞過來的div img id:==footer_left_div_id at list.html:166
 傳遞過來的title id:==header_title_span at list.html:167