html5 父页面调用子页面js方法

来源:互联网 发布:唐山网站怎么做seo 编辑:程序博客网 时间:2024/03/29 17:03

父页面代码:

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());}



0 0
原创粉丝点击