假设 url="http://write.blog.csdn.net/postedit?id=5&search=ok"
function getArgs() { var args = {}; //创建保存数据的对象 var qs = location.search.length > 0 ? location.search.substring(1) : ''; //取得查询字符串并去掉开头的问号 var items = qs.split('&'); //按&字符串拆分数组 var item = null, name = null, value = null; //逐个将每一项添加到args对象中 for (var i = 0; i < items.length; i++) { item = items[i].split('='); name = item[0]; value = item[1] args[name] = value; } return args; } var args = getArgs(); alert(args['id']); alert(args['search']);
时间: 2024-11-06 10:39:06