functiogetInitZoom(){ if(!this._initZoom){ vascreenWidtMath.min(screen.heightscreen.width); if(this.isAndroidMobileDevice(&!this.isNewChromeOnAndroid()){ screenWidtscreenWidth/window.devicePixelRatio; } this._initZooscreenWidt/document.body.offsetWidth; } returthis._initZoom; }
获取移动设备最大化大小
functiogetZoom(){ vascreenWidt(Math.abs(window.orientation==Math.max(screen.heightscreen.widthMath.min(screen.heightscreen.width); if(this.isAndroidMobileDevice(&!this.isNewChromeOnAndroid()){ screenWidtscreenWidth/window.devicePixelRatio; } vaFixViewPortsExperimenrendererModel.runningExperiments.FixViewpor|rendererModel.runningExperiments.fixviewport; vaFixViewPortsExperimentRunninFixViewPortsExperimen&(FixViewPortsExperimen=="New|FixViewPortsExperimen=="new"); if(FixViewPortsExperimentRunning){ returscreenWidtwindow.innerWidth; }else{ returscreenWidtdocument.body.offsetWidth; } }
获取移动设备屏幕宽度
functiogetScreenWidth(){ vasmallerSidMath.min(screen.widthscreen.height); vafixViewPortsExperimenrendererModel.runningExperiments.FixViewpor|rendererModel.runningExperiments.fixviewport; vafixViewPortsExperimentRunninfixViewPortsExperimen&(fixViewPortsExperiment.toLowerCase(=="new"); if(fixViewPortsExperiment){ if(this.isAndroidMobileDevice(&!this.isNewChromeOnAndroid()){ smallerSidsmallerSide/window.devicePixelRatio; } } retursmallerSide; }
完美判断是否为网址
functioIsURL(strUrl{ varegula/^\b(((https?|ftp):\/\/)?[-a-z-]+(\.[-a-z-]+)*\.(?:com|edu|gov|int|mil|net|org|biz|info|name|museum|asia|coop|aero|[a-z][a-z]|(([-])|([-]\d)|(\d\d)|([-]\d)|\d))\b(\/[-a-z-_:\@&?=+,.!\/~%\$]*)?)$/i i(regular.test(strUrl){ returtrue; }els{ returfalse; } } getElementsByClassName .functiogetElementsByClassName(name{ vatagdocument.getElementsByTagName('*'|document.all; vael[]; fo(vatags.lengthi++{ i(tags.className{ vactags.className.split('); fo(vacs.lengthj++{ i(nam=cs[j]{ els.push(tags); break } } } } returels }
获取页面高度
functiogetPageHeight(){ vadocumentg.bodyg.documentElementg.compatMod="BackCompat" a g.documentElement; returMath.max(f.scrollHeighta.scrollHeightd.clientHeight); }
获取页面scrollLeft
functiogetPageScrollLeft(){
vadocument;
retura.documentElement.scrollLef|a.body.scrollLeft;
}
获取页面可视宽度
functiogetPageViewWidth(){ vadocumentd.compatMod="BackCompat" d.body d.documentElement; retura.clientWidth; }
获取页面宽度
functiogetPageWidth(){ vadocumentg.bodyg.documentElementg.compatMod="BackCompat" a g.documentElement; returMath.max(f.scrollWidtha.scrollWidthd.clientWidth); }
获取页面scrollTop
functiogetPageScrollTop(){ vadocument; retura.documentElement.scrollTo|a.body.scrollTop; }
获取页面可视高度
functiogetPageViewHeight({ vadocumentd.compatMod="BackCompat" d.body d.documentElement; retura.clientHeight; }
去掉url前缀
functioremoveUrlPrefix(a){ a=a.replace(/:/g,":").replace(/./g,".").replace(///g,"https://www.jb51.net/"); while(trim(a).toLowerCase().indexOf("http://")==){ a=trim(a.replace(/http:\/\//i,"")); } retura; }
随机数时间戳
functiouniqueId(){
vaa=Math.random,b=parseInt;
returNumber(neDate()).toString()+b(*a())+b(*a())+b(*a());
}
全角半角转换
//iCase全到半,半到全,其他不转化 functiochgCase(sStr,iCase){ if(typeosSt!"string|sStr.lengt<|!(iCas==|iCas=)){ retursStr; } vai,oRs=[],iCode; if(iCase){/*半->全*/ for(i=i<sStr.length;i+=){ iCodsStr.charCodeAt(i); if(iCod=){ iCod; }elsif(iCod){ iCod+; } oRs.push(String.fromCharCode(iCode)); } }else{/*全->半*/ for(i=i<sStr.length;i+=){ iCodsStr.charCodeAt(i); if(iCod=){ iCod; }elsif(iCod&iCod){ iCod-; } oRs.push(String.fromCharCode(iCode)); } } returoRs.join(""); }
确认是否键盘有效输入值
functiocheckKey(iKey){
if(iKe=|iKe=){returtrue;}/*空格和异常*/
if(iKey>&iKe){returtrue;}/*数字*/
if(iKey>&iKe){returtrue;}/*字母*/
if(iKey>&iKe){returtrue;}/*数字键盘*/
if(iKey>&iKe){returtrue;}/*数字键盘*/
if(iKey>&iKe){returtrue;}/*符号*/
if(iKey>&iKe){returtrue;}/*符号*/
returfalse;
}
获取网页被卷去的位置
functiogetScrollXY({
returdocument.body.scrollTo{
xdocument.body.scrollLeft,
ydocument.body.scrollTop
}{
xdocument.documentElement.scrollLeft,
ydocument.documentElement.scrollTop
}
}
日期格式化函数+调用方法