代码与页面的分离(5)
var reg = new RegExp("{(\\w*)}","ig");
var str = new String(this[name]);
var arr = str.match(reg);
var i;
if(arr != null)
for(i=0;i<arr.length;i++)
{
key = arr.slice(1,-1);
reg = new RegExp(arr,"ig");
if(this[key]!=null)
str = str.replace(reg,this[key]);
}
return str;
}
function Template_Split(name)
{
var len = 0;
var arr;
if(this[name]==null)
return;
var Template_Exp = new RegExp("<!--#TPLDEF +(\\w*) *-->((.|\\n)*)<!--#TPLEND +\\1 *-->","i");
while(this[name].search(Template_Exp)!=-1)
{
arr = this[name].match(Template_Exp);
this[arr[1} = arr[2];
this[name] = this[name].replace(Template_Exp,"{"+arr[1]+"}");
this.Split(arr[1]);
}
}
function Template_Load(name,filename)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.BuildPath(this.TplPath, filename);
if(fso.FileExists(file))
{
var f = fso.OpenTextFile(file, 1);
this[name] = f.ReadAll();
}
}
//Template Constructor
function Template(path)
{
//Property
this.TplPath = path;
//Method
this.Parse = Template_Parse;
this.Split = Template_Split;
this.Load = Template_Load;
}
%>
内容版权声明:除非注明,否则皆为本站原创文章。