在分析URL参数时中文出现undefined,求高手解决!
function Request(strParame)
{
var args = new Object();
var query = "http://localhost/index.asp?name=中文&height=100";
var pairs = query.split("&"); // Break at ampersand
for(var i = 0; i < pairs.length; i++)
{
var pos = pairs[i].indexOf('=');
if (pos == -1) continue;
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
value = decodeURIComponent(value);
args[argname] = value;
//alert(args[argname]);//这里还正常呢,
}
//alert(args[strParame]);//到那个中文就成了undefined了,英文就没事这是什么原因有什么解决办法吗?
return args[strParame];
}
var name=Request('name');
alert(name);
------解决方案--------------------参考:http://www.w3school.com.cn/js/jsref_decodeURIComponent.asp
------解决方案--------------------
function QueryString(fieldName) {
var urlString = "http://localhost/index.asp?name=中文&height=100";
if (urlString != null) {
var typeQu = fieldName + "=";
var urlEnd = urlString.indexOf(typeQu);
if (urlEnd != -1) {
var paramsUrl = urlString.substring(urlEnd + typeQu.length);
var isEnd = paramsUrl.indexOf('&');