您好,欢迎访问一九零五行业门户网

javaScript 查询字符串参数 获取

function getquerystringargs() { //取得查询字符串并去掉开头的问号 var qs = (location.search.length > 0 ? location.search.substring(1) : ); //保存数据对象 args = {}; //取得每一项 items = qs.length ? qs.split(&) : [], item = null; name = null; value = null; //for循环 i = 0; len = items.length; //将每一项加入args对象中 for (i = 0; i < len; i++) { item = items[i].split(=); name = decodeuricomponent(item[0]); value = decodeuricomponent(item[1]); if (name.length) { args[name] = value; } } return args; } //假设 ?q=javascript&num=10 var args = getquerystringargs(); alert(args[q]); alert(args[num]);
其它类似信息

推荐信息