javascript 取URL地址参数
跳转页面:
location.href = 'index.html?account=' + account + '&UserID=' + json.UserID + '&BaseUrl=' + Service + '&GroupCode=' + json.GroupCode + '';
获取当前URL地址:
var url = self.location.href;
取URL地址参数:
<script language="javascript" type="text/javascript"> //var url="http://xxx.action?a=12313&b=asdad&c=aasda&d=iiyiujh&h=ertrt"; var url = "http://blog.sina.com.cn/ebmd?account=indogps&UserID=2&BaseUrl=http://www.muliatrack.com/wspub1/service.asmx&GroupCode=1,25,28"; var a = function(){ if (url.indexOf("=") != -1) { var start = url.indexOf("=") + 1; var result = new Array(); var i = 0;
if (url.search("&") > 0) { var end = url.indexOf("&"); result[i] = url.substring(start, end); start = url.indexOf("=", end) + 1; while (url.indexOf("&", start) != -1) { end = url.indexOf("&", start); result[++i] = url.substring(start, end); start = url.indexOf("=", end) + 1; } start = url.indexOf("=", end) + 1; result[++i] = url.substring(start, url.length); } return result; } return "没有参数!";
};
alert(a()[3]) //调用函数
</script>
js时间:
Date.prototype.format = function(format) { var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(), //minute "s+" : this.getSeconds(), //second "q+" : Math.floor((this.getMonth()+3)/3), //quarter "S" : this.getMilliseconds() //millisecond } if(/(y+)/.test(format)) format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length)); for(var k in o) if(new RegExp("("+ k +")").test(format)) format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); return format; }
调用:
var now = new Date();
now = now.format("yyyy-MM-dd hh:mm:ss");
时间差:
function dateOnLine(sDate1, sDate2, mode) { //sDate1和sDate2是2004-10-18格式 var iDays var date1 = new Date(Date.parse(sDate1.replace(/-/g, "/"))); //转换成Data(); var date2 = new Date(Date.parse(sDate2.replace(/-/g, "/"))); //转换成Data(); if (mode == "dd") { iDays = parseInt(Math.abs(date1 - date2) / 1000 / 60 / 60 / 24); //把相差的毫秒数转换为天数 } else if (mode == "mm") { iDays = parseInt(Math.abs(date1 - date2) / 1000 / 60); //把相差的毫秒数转换为分钟 } return iDays; }
调用:
var now = new Date();
now = now.format("yyyy-MM-dd hh:mm:ss");
rcv_time = new Date(vehicle.active_gps_data.rcv_time);
rcv_time = rcv_time.format("yyyy-MM-dd hh:mm:ss");
var m = dateOnLine(now, rcv_time, "mm");