html:
<div id="netCheckMask">
<div class="netCheck">
<h1 style="text-align: center;display: block;width: 100%;position: absolute;top: 5%;">网络错误</h1>
<form class="mui-input-group btngroups">
<div class="mui-button-row">
<button οnclick="tryAgain()" type="button" class="mui-btn mui-btn-primary" >重试</button>
<button οnclick="exit()" type="button" class="mui-btn mui-btn-danger" >退出</button>
</div>
</form>
</div>
</div>
js:
function tryAgain(){
if(plus.networkinfo.getCurrentType() != plus.networkinfo.CONNECTION_NONE) {
document.getElementById("netCheckMask").style.display = "none";
}else{
mui.toast("网络错误",{duration:10000,type:"div"})
}
}
function initCheck(){
setInterval(function(){
if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
document.getElementById("netCheckMask").style.display = "block"
}
},50)
}
plus.runtime.quit();
}
css:
<style type="text/css">#netCheckMask {
background: rgba(0, 0, 0, 0.8);
width: 100%;
height: 100%;
position: fixed;
top: 0;
z-index: 999;
display: none;
}
.netCheck {
background: #fff;
width: 50%;
height: 30%;
margin: 25%;
border-radius: 15px;
position: relative;
}
.btngroups {
display: block;
width: 100%;
position: absolute;
bottom: 10%;
}</style>
使用方法:mui.init()
mui.plusReady(function() {
initCheck();
})