判断设备,时间戳转化为时间,获取URL中的参数等常用方法

判断设备

function IsPC() {
   var userAgentInfo = navigator.userAgent;
   var Agents = ["Android", "iPhone","SymbianOS", "Windows Phone","iPad", "iPod"];
   var flag = true;
   for (var v = 0; v < Agents.length; v++) {
      if (userAgentInfo.indexOf(Agents[v]) > 0) {
         flag = false;
         break;
      }
   }
   return flag;
}


时间戳转化为时间

function formatDate(now)   {
    if(now == null || now == ""){
	return "";
    }
    var date_now = new Date(now)     
    var year=date_now.getFullYear();     
    var month=date_now.getMonth()+1;     
    var date=date_now.getDate();     
    var hour=date_now.getHours();     
    var minute=date_now.getMinutes();     
    var second=date_now.getSeconds();     
    return year +"-"+ (month<10? "0"+month: month) +"-"+ (date<10? "0"+date: date) +" " + (hour<10? "0"+hour: hour) + ":" + (minute<10? "0"+minute: minute) + ":" + (second<10? "0"+second: second);             
} 

获取URL中的参数

function GetUrl() {   
	var url = location.search; //获取url中"?"符后的字串   
	var theRequest = new Object();   
	if (url.indexOf("?") != -1) {   
		var str = url.substr(1);   
		strs = str.split("&");   
		for(var i = 0; i < strs.length; i ++) {   
 			theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);   
		}   
	}   
	return theRequest;   
}


禁止页面滚动

//实现滚动条无法滚动
var mo=function(e){e.preventDefault();};

/***禁止滑动***/
function stop(){
    document.body.style.overflow='hidden';        
    document.addEventListener("touchmove",mo,false);//禁止页面滑动
}
/***取消滑动限制***/
function move(){
    document.body.style.overflow='';//出现滚动条
    document.removeEventListener("touchmove",mo,false);        
}


你可能感兴趣的:(JavaScript)