19
2019
06

js 获取 url 后面参数

  //获取url后缀参数


例:

url:是 http://www.baidu.com/s?username=hello


   function t_parseParam(name) {

   var b=new RegExp("(^|\\?|&)"+name+"=([^&]*)(\\s|&|$)","i");

if(b.test(location.href)){

return unescape(RegExp.$2.replace(/\+/g," "));

}

return "";

    }

调用:

 t_parseParam('username');

j结果:

hello


« 上一篇 下一篇 »