准备函数
//Mui准备函数 mui.ready(function(){ //执行方法体 }); //Html5+准备函数 mui.plusReady(function(){ //执行方法体 })重写mui和doncument
<div id="a">点我</div> //这四种点击方法效果相同 (function($, doc){ /*mui("body").on("tap", "#a", function(){ alert("mui点击成功") })*/ /*$("body").on("tap", "#a", function(){ alert("$点击成功") })*/ /*document.getElementById("a").addEventListener("tap",function(){ alert("document点击成功") })*/ /*doc.getElementById("a").addEventListener("tap",function(){ alert("doc点击成功") })*/ }(mui, document))等待框、消息框
plus.nativeUI.showWaiting("等待中…"); plus.nativeUI.closeWaiting(); plus.nativeUI.alert("消息框");点击事件
<body> <div id="a">点我</div> </body> //点击body里面的id为a的标签 mui("body").on("tap","#a",function(){ alert("点击成功") }) //直接为id为a的标签添加点击事件 document.getElementById("a").addEventListener("tap",function(){ alert("点击成功") })触发指定页面事件
//触发url页面的show事件 $.fire('url', 'show', null);打开页面 1.简单的打开
mui.openWindow({ url: 'unlock.html', id: 'unlock', show: { aniShow: 'pop-in' }, waiting: { autoShow: false //在页面unlock.html加载完成后,unlock.html不会显示 } });2.加载后显示
//第一步:在A.html写如下方法加载B.html页面 mui.openWindow({ url: 'B.html', show:{ autoShow:false //在页面B.html加载完成后,B.html不会显示 } }); //第二步:在B.html页面写以下方法,B页面onload从服务器获取列表数据; window.onload = function(){ mui.plusReady(function(){ //关闭等待框 plus.nativeUI.closeWaiting(); //显示当前页面 mui.currentWebview.show(); }); }页面预加载
// 页面预加载 var baidu = mui.preload({ id: "baidu", url: "http://www.baidu.com", }); // 监听预加载完成 baidu.addEventListener("loaded",function () { alert("baidu预加载成功") }); // 10s后从右向左滑入(pop-in)id为baidu的页面 setTimeout(function(){ /*var bd = plus.webview.getWebviewById("baidu");//取得id为baidu的页面 bd.show("pop-in");*/ //显示 baidu.show("pop-in"); },10000)打开已经打开过的页面
var bd = plus.webview.getWebviewById("baidu");//取得id为baidu的页面 bd.show("pop-in"); //显示