墨色风雨
解决了写一个我自己的没有想象的那么困难是我自己想复杂了functiononNetChange(){varnt=plus.networkinfo.getCurrentType();if(nt=="2"||nt=="3"||nt=="5"||nt=="6"){mui.toast("在线模式");plus.device.vibrate();s=plus.audio.createPlayer("../audio/NetYes.mp3");varnum=s.getDuration();//获取音频总长度numbersetTimeout(function(){//延时获取,否则可能没有返回长度varnum=s.getDuration();//alert(num)},100)s.play(function(){//播放完成回调//alert("Audioplaysuccess!");},function(e){//失败回调//alert("Audioplayerror:"+e.message);});vartx=db.transaction("users",READ_WRITE);varstore=tx.objectStore("users");varindex=store.index("Ifnet");varreq=index.openCursor(IDBKeyRange.only("1"));varodiv=document.getElementById("tijiao");if(odiv.style.display="none"){odiv.style.display="block";}req.onsuccess=function(evt){varres=evt.target.result;if(res){varnet=[res.value]varj=0;functionsubmit(){if(j>=net.length){return;}mui.ajax('http://',{data:{tugwork_s_id:net[j].TUGWORK_S_ID,IsMooring:net[j].If_mooring,IsPickup:net[j].ISPICKUP,godate:net[j].Godate,startdate:net[j].Startdate,enddate:net[j].Enddate,backdate:net[j].Backdate},dataType:'json',//服务器返回json格式数据type:'post',//HTTP请求类型timeout:5000,//超时时间设置为10秒;success:function(req){console.log(JSON.stringify(req));j++;submit();},error:function(xhr,type,errorThrown){console.log('Update_local');}});}submit();res.continue();}};req.οnerrοr=function(evt){console.error("UpDataerror:",evt.target.errorCode||evt.target.error);};setTimeout(function(){odiv.style.display="none";},3000);}else{mui.toast("离线模式");plus.device.vibrate();s=plus.audio.createPlayer("../audio/NetNo.mp3");varnum=s.getDuration();//获取音频总长度numbersetTimeout(function(){//延时获取,否则可能没有返回长度varnum=s.getDuration();//alert(num)},100)s.play(function(){//播放完成回调//alert("Audioplaysuccess!");},function(e){//失败回调//alert("Audioplayerror:"+e.message);});}}