如何从javascript获取参数?http://domain.com/page.html?returnurl=%2Fadmin为js内page.html,它怎么能收回GET参数?对于上面的简单示例,func('returnurl')应该是/admin但它也适用于复杂的查询.。
3 回答
江户川乱折腾
TA贡献1851条经验 获得超5个赞
window.location.search.substr(1)
returnurl=%2Fadmin
编辑
function findGetParameter(parameterName) { var result = null, tmp = []; location.search .substr(1) .split("&") .forEach(function (item) { tmp = item.split("="); if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); }); return result;}
decodeURIComponent
function findGetParameter(parameterName) { var result = null, tmp = []; var items = location.search.substr(1).split("&"); for (var index = 0; index < items.length; index++) { tmp = items[index].split("="); if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); } return result;}
添加回答
举报
0/150
提交
取消