1. <tt id="5hhch"><source id="5hhch"></source></tt>
    1. <xmp id="5hhch"></xmp>

  2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

    <rp id="5hhch"></rp>
        <dfn id="5hhch"></dfn>

      1. Javascript

        時間:2024-07-29 10:09:57 JavaScript 我要投稿

        Javascript模板

          /***Template.class.js***/

          functionTemplate()

          {

          this.classname="Template";

          this.debug=false;

          this.file=newHashMap();

          this.root="";

          this.varkeys=newHashMap();

          this.varvals=newHashMap();

          this.unknowns="remove";

          this.halt_on_error="yes";

          this.last_error="";

          this.fso=newActiveXObject("Scripting.FileSystemObject");

          this.set_root=_set_root;

          this.set_unknowns=_set_unknowns;

          this.get_var=_get_var;

          this.set_file=_set_file;

          this.set_var=_set_var;

          this.set_block=_set_block;

          this.subst=_subst;

          this.parse=_parse;

          this.p=_p;

          this.pparse=_pparse;

          this.finish=_finish;

          this.loadfile=_loadfile;

          this.is_dir=_is_dir;

          this.file_exists=_file_exists;

          this.filename=_filename;

          this.varname=_varname;

          this.halt=_halt;

          this.haltmsg=_haltmsg;

          }

          /**

          *設置模板文件根目錄

          *@paramroot

          */

          function_set_root(root)

          {

          if(!this.is_dir(root))

          {

          this.halt("set_root:"+root+"isnotadirectory.");

          }

          this.root=root;

          }

          /**

          *設定對未知模板變量的處理辦法

          *@paramunknowns

          */

          function_set_unknowns(unknowns)

          {

          this.unknowns=unknowns;

          }

          /**

          *設定模板文件

          *@paramhandle

          *@paramfilename

          */

          function_set_file(handle,filename)

          {

          this.file.put(handle,this.filename(filename));

          }

          /**

          *設定模板變量

          *@paramvarname

          *@paramvalue

          */

          function_set_var(varname,value)

          {

          if(!this.varkeys.containsKey(varname))

          {

          this.varkeys.put(varname,this.varname(varname));

          }

          if(!this.varvals.containsKey(varname))

          {

          this.varvals.put(varname,value);

          }

          else

          {

          this.varvals.remove(varname);

          this.varvals.put(varname,value);

          }

          //alert(varname+"=================="+value);

          }

          /**

          *設定塊變量

          *@paramparent

          *@paramhandle

          *@paramname

          */

          function_set_block(parent,handle,name)

          {

          if(!this.loadfile(parent))

          {

          this.halt("subst:unabletoload"+parent);

          }

          if(name=="")

          {

          name=handle;

          }

          varstr=this.get_var(parent);

          varre=newRegExp("([sS.]*)");

          //Matcherm=p.matcher(str);

          //varrs=m.find();

          //vart=m.group(m.groupCount());

          //this.set_var(handle,t);

          vararr=re.exec(str);

          if(arr!=null)

          this.set_var(handle,RegExp.$1);

          str=str.replace(re,"{"+name+"}");

          this.set_var(parent,str);

          }

          /**

          *進行變量替換

          *@paramhandle

          *@return

          */

          function_subst(handle)

          {

          if(!this.loadfile(handle))

          {

          this.halt("subst:unabletoload"+handle);

          }

          varstr=this.get_var(handle);

          varkeys=this.varkeys.keySet();

          //alert(keys.length);

          for(vari=0;i<keys.length;i++)

          {

          varkey=keys[i];

          varre=newRegExp(this.varkeys.get(key),"g")

          str=str.replace(re,this.varvals.get(key));

          }

          //alert(handle+"++++++++++++++++++"+str);

          returnstr;

          }

          /**

          *進行變量復制

          *@paramtarget

          *@paramhandle

          *@paramappend

          */

          function_parse(target,handle,append)

          {

          varstr=this.subst(handle);

          if(append)

          {

          this.set_var(target,this.get_var(target)+str);

          }

          else

          {

          this.set_var(target,str);

          }

          }

          /**

          *返回替換后的文件

          *@paramvarname

          *@return

          */

          function_p(varname)

          {

          returnthis.finish(this.get_var(varname));

          }

          /**

          *parse()和p()的合并

          *@paramtarget

          *@paramhandle

          *@paramappend

          *@return

          */

          function_pparse(target,handle,append)

          {

          this.parse(target,handle,append);

          document.writeln(this.p(target));

          }

          /**

          *加載模板文件

          *@paramhandle

          *@return

          */

          function_loadfile(handle)

          {

          if(this.varkeys.containsKey(handle)&&this.varvals.get(handle)!=null)

          {

          returntrue;

          }

          if(!this.file.containsKey(handle))

          {

          _halt("loadfile:"+handle+"isnotavalidhandle.");

          returnfalse;

          }

          varfilename=this.file.get(handle);

          if(!this.file_exists(filename))

          {

          this.halt("loadfile:whileloading"+handle+","+filename+"doesnotexist.");

          returnfalse;

          }

          try

          {

          varfr=this.fso.OpenTextFile(filename);

          vars=fr.ReadAll();

          if(s=="")

          {

          halt("loadfile:whileloading"+handle+","+filename+"isempty.");

          returnfalse;

          }

          this.set_var(handle,s);

          }

          catch(e)

          {

          }

          returntrue;

          }

          /**

          *獲取變量

          *@paramvarname

          *@return

          */

          function_get_var(varname)

          {

          if(this.varvals.containsKey(varname))

          returnthis.varvals.get(varname);

          else

          return"";

          }

          /**

          *判斷目錄

          *@parampath

          *@return

          */

          function_is_dir(path)

          {

          if(this.fso.FolderExists(path))

          returntrue;

          else

          returnfalse;

          }

          /**

          *判斷文件

          *@paramfilename

          *@return

          */

          function_file_exists(filename)

          {

          if(this.fso.FileExists(filename))

          returntrue;

          else

          returnfalse;

          }

          /**

          *文件名處理

          *@paramfilename

          *@return

          */

          function_filename(filename)

          {

          if(!this.file_exists(this.root+filename))

          {

          this.halt("filename:file"+filename+"doesnotexist.");

          }

          returnthis.root+filename;

          }

          /**

          *變量名處理

          *@paramvarname

          *@return

          */

          function_varname(varname)

          {

          return"{"+varname+"}";

          }

          /**

          *完成字符串的處理

          *@paramstr

          *@return

          */

          function_finish(str)

          {

          varre=newRegExp("{[^trn}]+}","g");

          if(this.unknowns=="remove")

          {

          str=str.replace(re,"");

          }

          elseif(this.unknowns=="comment")

          {

          str=str.replace(re,"");

          }

          else

          {

          }

          returnstr;

          }

          function_halt(msg)

          {

          this.last_error=msg;

          if(this.halt_on_error!="no")

          {

          _haltmsg(msg);

          }

          if(this.halt_on_error=="yes")

          {

          alert("Halted.");

          //System.exit(0);

          }

          }

          function_haltmsg(msg)

          {

          alert("TemplateError:"+msg);

          }

          /**

          *HashMap構造函數

          */

          functionHashMap()

          {

          this.length=0;

          this.prefix="hashmap_prefix_20050524_";

          }

          /**

          *向HashMap中添加鍵值對

          */

          HashMap.prototype.put=function(key,value)

          {

          this[this.prefix+key]=value;

          this.length++;

          }

          /**

          *從HashMap中獲取value值

          */

          HashMap.prototype.get=function(key)

          {

          returntypeofthis[this.prefix+key]=="undefined"

          ?null:this[this.prefix+key];

          }

          /**

          *從HashMap中獲取所有key的集合,以數組形式返回

          */

          HashMap.prototype.keySet=function()

          {

          vararrKeySet=newArray();

          varindex=0;

          for(varstrKeyinthis)

          {

          if(strKey.substring(0,this.prefix.length)==this.prefix)

          arrKeySet[index++]=strKey.substring(this.prefix.length);

          }

          returnarrKeySet.length==0?null:arrKeySet;

          }

          /**

          *從HashMap中獲取value的集合,以數組形式返回

          */

          HashMap.prototype.values=function()

          {

          vararrValues=newArray();

          varindex=0;

          for(varstrKeyinthis)

          {

          if(strKey.substring(0,this.prefix.length)==this.prefix)

          arrValues[index++]=this[strKey];

          }

          returnarrValues.length==0?null:arrValues;

          }

          /**

          *獲取HashMap的value值數量

          */

          HashMap.prototype.size=function()

          {

          returnthis.length;

          }

          /**

          *刪除指定的值

          */

          HashMap.prototype.remove=function(key)

          {

          this[this.prefix+key];

          this.length--;

          }

          /**

          *清空HashMap

          */

          HashMap.prototype.clear=function()

          {

          for(varstrKeyinthis)

          {

          if(strKey.substring(0,this.prefix.length)==this.prefix)

          this[strKey];

          }

          this.length=0;

          }

          /**

          *判斷HashMap是否為空

          */

          HashMap.prototype.isEmpty=function()

          {

          returnthis.length==0;

          }

          /**

          *判斷HashMap是否存在某個key

          */

          HashMap.prototype.containsKey=function(key)

          {

          for(varstrKeyinthis)

          {

          if(strKey==this.prefix+key)

          returntrue;

          }

          returnfalse;

          }

          /**

          *判斷HashMap是否存在某個value

          */

          HashMap.prototype.containsValue=function(value)

          {

          for(varstrKeyinthis)

          {

          if(this[strKey]==value)

          returntrue;

          }

          returnfalse;

          }

          /**

          *把一個HashMap的值加入到另一個HashMap中,參數必須是HashMap

          */

          HashMap.prototype.putAll=function(map)

          {

          if(map==null)

          return;

          if(map.constructor!=JHashMap)

          return;

          vararrKey=map.keySet();

          vararrValue=map.values();

          for(variinarrKey)

          this.put(arrKey[i],arrValue[i]);

          }

          //toString

          HashMap.prototype.toString=function()

          {

          varstr="";

          for(varstrKeyinthis)

          {

          if(strKey.substring(0,this.prefix.length)==this.prefix)

          str+=strKey.substring(this.prefix.length)

          +":"+this[strKey]+"rn";

          }

          returnstr;

          }

          <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"

          "http://www.w3.org/TR/html4...

          {HEAD}

          {WELCOME}


             
        {NUMBER}

          {FOOT}

          vartmplt=newTemplate();

          varroot=location.href;

          root=unescape(root.substring(8,root.lastIndexOf("/")+1));

          tmplt.set_root(root);

          tmplt.set_file("fh","tpl/main.htm");

          tmplt.set_file("head","tpl/head.htm");

          tmplt.set_file("foot","tpl/foot.htm");

          tmplt.set_block("fh","BROWS","rows");

          tmplt.set_block("BROWS","BCOLS","cols");

          tmplt.set_var("WELCOME","歡迎光臨");

          for(vari=0;i<10;i++)

          {

          tmplt.set_var("cols","");

          for(varj=0;j<10;j++)

          {

          tmplt.set_var("NUMBER",i+"."+j);

          tmplt.parse("cols","BCOLS",true);

          }

          tmplt.parse("rows","BROWS",true);

          }

          tmplt.parse("HEAD","head",false);

          tmplt.parse("FOOT","foot",false);

          tmplt.pparse("out","fh",false);

        【Javascript】相關文章:

        對javascript的理解08-08

        常用的JavaScript模式09-22

        Javascript的this用法簡述08-15

        JavaScript學習筆記08-24

        JavaScript 基礎教學09-29

        JavaScript的課堂講解09-03

        JavaScript常用方法匯總10-25

        JavaScript數組常用方法介紹09-04

        JavaScript中的with關鍵字07-24

        高效編寫JavaScript代碼的技巧08-25

        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码

        1. <tt id="5hhch"><source id="5hhch"></source></tt>
          1. <xmp id="5hhch"></xmp>

        2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

          <rp id="5hhch"></rp>
              <dfn id="5hhch"></dfn>