html5 父頁面呼叫子頁面js方法
阿新 • • 發佈:2019-02-07
父頁面程式碼:
var randid=result.rows.item(0)['id'];
plus.webview.close("test_order_detail");//建立之前要關閉一次,因為這個方法是重複使用的,不會報錯的
sub = plus.webview.create("test_order_detail.html","test_order_detail",subpage_style,{qid:randid});
sub.show();//這個方法是關鍵
建立子頁面一定要新增隨機數作為引數的。
說明:mui('.mui-bar-tab').on('tap', 'a', function(e) { <span style="white-space:pre"> </span>var targetTab = this.getAttribute('href'); <span style="white-space:pre"> </span>if(targetTab=="clearContent"){ <span style="white-space:pre"> </span>gettest(); //就是上邊的方法 <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>if(targetTab=="detail"){ <span style="white-space:pre"> </span>var detail=plus.webview.getWebviewById("test_order_detail"); <span style="white-space:pre"> </span>detail.evalJS("showdetail()");//這裡也可以直接寫js方法 <span style="white-space:pre"> </span>} });
test_order_detail:子頁面ID;
showdetail:方法在子頁面定義。
子頁面:
子頁面通過父頁面傳的引數qid載入資料,主內容顯示在dcontent中,父頁面如果
function showdetail(){
$("#dcontent").show();
alert($("#dcontent").text());
}