JScript 客戶端 自寫 Request 對象

var Request =
{
QueryString: new ThunderBirdRequestQueryString(),
Cookies: new ThunderBirdRequestCookies()
}
function ThunderBirdRequestQueryString()
{
this.Current = document.location.search;
this.count = 0;
this.Item = new Array();
this.item = function (strKey)
{
  if ( typeof(this.Item[strKey]) != "undefined" )
  {
   return this.Item[strKey];
  }
  else
  {
   return "";
  }
}
ThunderBirdRequestOnInit(/([^?&][a-z/d]*)=([^#&]*)/gim, this.Current, this.count, this.Item);
}
function ThunderBirdRequestCookies()
{
this.Current = document.cookie;
this.count = 0;
this.Item = new Array();
this.item = function (strKey)
{
  if ( typeof(this.Item[strKey]) != "undefined" )
  {
   return this.Item[strKey];
  }
  else
  {
   return "";
  }
}
ThunderBirdRequestOnInit(/([^?&][a-z/d]*)=([^#&;]*)/gim, this.Current, this.count, this.Item);
}
function ThunderBirdRequestOnInit(RegExpRule, Current, count, Item)
{
if ( Current != "" )
{
  while ( RegExpRule.exec(Current) != null )
  {
   Item[RegExp.$1] = RegExp.$2;
   Item[count] = RegExp.$2;
   count += 1;
  }
}
}

幾經修改 纔出來這個

用過 Scripting.Dictionary 也用過 類型屬性 最後還是用回 數組

使用方法

document.write( Request.QueryString.item("test") );

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章