重定向到 home.html 页面后,我可以看到我在上一页中给出的查询字符串值。
Home.html?FirstName=dd&LastName=ee&smtButton=Submit
我得到的结果是:
firstname = undefined
lastname = undefined
age = undefined
谁能帮我解决这个问题?
JS:
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx + 1, document.URL.length).split('&');
for (var i = 0; i < pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}
params = getParams();
firstname = unescape(params["firstname"]);
lastname = unescape(params["lastname"]);
age = unescape(params["age"]);
document.write("firstname = " + firstname + "<br>");
document.write("lastname = " + lastname + "<br>");
document.write("age = " + age + "<br>");