HTML 传递参数的处理 待续....
<
script
>
var HtmlParam = function () ... {
this.baseUrl = document.loaction.href;//"http://www.OMyOS.com/?type=print&id=n1&ok=j";
this.param = this.baseUrl.substring(this.baseUrl.lastIndexOf("?")+1,this.baseUrl.length);
this.arrParam = this.param.split("&");
this.paramMap = ...{};
//设置参数Map
this.put = function(key, value)...{
this.paramMap[key] = value;
};
//提取参数的值,根据key
this.get = function(key) ...{
return this.paramMap[key];
};
for (var i = 0;i < this.arrParam.length ;i++ )...{
var item = this.arrParam[i];
var key = item.substring(0, item.lastIndexOf("="));
var value = item.substring(item.lastIndexOf("=")+1, item.length);
this.put(key, value);
}
}
var htmlParam = new HtmlParam();
alert(htmlParam.get( " type " ));
</ script >
var HtmlParam = function () ... {
this.baseUrl = document.loaction.href;//"http://www.OMyOS.com/?type=print&id=n1&ok=j";
this.param = this.baseUrl.substring(this.baseUrl.lastIndexOf("?")+1,this.baseUrl.length);
this.arrParam = this.param.split("&");
this.paramMap = ...{};
//设置参数Map
this.put = function(key, value)...{
this.paramMap[key] = value;
};
//提取参数的值,根据key
this.get = function(key) ...{
return this.paramMap[key];
};
for (var i = 0;i < this.arrParam.length ;i++ )...{
var item = this.arrParam[i];
var key = item.substring(0, item.lastIndexOf("="));
var value = item.substring(item.lastIndexOf("=")+1, item.length);
this.put(key, value);
}
}
var htmlParam = new HtmlParam();
alert(htmlParam.get( " type " ));
</ script >
一段小代码,不过很好用.现在HTML静态页面越来越多了. HTML文件也有它的局限性,无法像ASP,JSP,PHP那些服务器支持的语言一下通过Request来获取传递. 因此失去很灵活性的操作性.此段代码就为解决这个问题页设计的.
还望各位同行给点指点.3Q!