日期:2014-05-18  浏览次数:20427 次

javascript 取url的值
http:www.baidu.com?wd=mm&cl=3我怎么用javascript截取到第二个=号后面的3,第二个=号前面和后面的字
或者说是我怎么能取到cl的值?

------解决方案--------------------
var str = "http://localhost/aaa.aspx?aa=1&bb=2&cc=3&dd=4afasfsf "; alert(GetQueryString(str, "aa ")); alert(GetQueryString(str, "bb ")) alert(GetQueryString(str, "cc ")) alert(GetQueryString(str, "dd ")) function GetQueryString(url,key) { var reg = new RegExp( ".*? "+ key+ "=([^&]*)?&.*?$ "+ "|.*? "+key+ "=([^&]*)?$| "); if(reg.exec(url) == url) return " "; return url.replace(reg, "$1$2 "); // return reg.exec(url)[0].Value; }