JS采用正则表达式简单获取URL地址栏参数

GetUrlParam:function GetUrlParam(param){
var reg = new RegExp("(^|&)"+ param +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
},


param:传入参数名字

例:

var docId = "101";

var randnum = Math.random();

url="../page/jtformat?docId="+docId+"&randnum="+randnum;

this.GetUrlParam(docId)返回101;

this.GetUrlParam(randnum)返回随机数randnum;

上一篇:利用scrapy-client 发布爬虫到远程服务端


下一篇:Android,不小心关闭了某个小窗口怎么恢复,方法介绍