输出为:
思路:供学习!!
/* https://www.baidu.com/s?name=avery&age=20&sex=male&like=talkwithothers 取出name,age和sex的值 */ var str = "https://www.baidu.com/s?name=avery&age=20&sex=male&like=talkwithothers"; var st1 = str.split("?"); var arr = st1[1]; var st2 = arr.split("&"); for (var i=0;i<=st2.length-1;i++) { var ss = st2[i].split("="); var dd = ss[0]; var ff = ss[1]; if (ff!="") { document.write(" "+dd+":"+ff+""); } }