«
服务端 VBScript 与 JScript 几个相同特性的写法

时间:2008-5-31    作者:Deri    分类: 分享


   <p>  1. 遍历集合/对象</p><p>  1.1 VBScript 遍历表单集合</p><p>  linenum</p><code><%<br />  for each temp in request.Form<br />    response.write temp&": "&request.form(temp)<br />  next<br />%></code></p><p>  1.2 JScript 遍历表单集合</p><p>  linenum</p><code><%<br />  for (var $e=new Enumerator(Request.Form); !$e.atEnd(); $e.moveNext()){<br />    Response.Write($e.item()+':<br/> '+Request.Form($e.item()));<br />  }<br />%></code></p><p>  2. 转变量值为变量, 并赋值</p><p>  2.1 VBScript 转变量值为变量并赋值</p><p>  linenum</p><code><%<br />  for each temp in request.Form<br />    execute temp&"=request.form(temp)"<br />  next<br />%></code></p><p>  2.2 JScript 转变量值为变量并赋值</p><p>  linenum</p><code><%<br />  var $xml=new ActiveXObject("microsoft.xmldom");<br />    $xml.load(Server.MapPath('config.xml'));<br />    var $childNodes=$xml.documentElement.selectSingleNode('//siteconfig').childNodes<br />    <br />    for ($e=new Enumerator($childNodes); !$e.atEnd(); $e.moveNext()){<br />      eval($e.item().nodeName+"=$e.item().text");<br />    }<br />  $xml=null;<br />    Response.Write(sitekeywords);<br />%></code></p><p>  3. 动态包含文件</p><p>  3.1 VBScript 动态包含文件</p><p>  linenum</p><code><%<br /> function fInclude(filepath)<br /> ' sample call '''/// execute fInclude("include/system/language/"&sitefglang&"/main.asp") '''<br />   dim cnt<br />     cnt=CreateObject("scripting.fileSystemObject").openTextFile(server.MapPath(filepath)).readall<br />     cnt=replace(cnt,"<"&chr(37),"")<br />     cnt=replace(cnt,chr(37)&">","")<br />     fInclude=cnt<br /> end function 'shawl.qiu code'<br />  execute fInclude("include/system/language/"&sitefglang&"/main.asp")<br />%></code></p><p>  3.2 JScript 动态包含文件</p><p>  linenum</p><code><%<br />  eval($dynInc('aj2.asp'));<br />  Response.Write($test);<br />  <br />  function $dynInc($fl){<br />  /* ------------------------------------<br />  * 服务端 JScript 动态包含文件 By shawl.qiu<br />  * sample call: eval($dynInc('aj2.asp')); <br />  *------------------------------------*/<br />    var $fso=new ActiveXObject("scripting.fileSystemObject");<br />      $str=$fso.OpenTextFile(Server.MapPath($fl)).ReadAll();<br />      $str=$str.replace(/<%|%>/g,'');<br />    $fso=null;<br />    return $str;<br />  }<br />%></code></p>