♣
asp中条件式包含某个文件(再次发问)
想在asp中条件式包含某个文件
ssi的include指令应该是不行的,它是先于其它脚本代码执行的,还有没有其它的方法呢
想实现像php里面的:
switch($n) {
case "news" : require_once news_list.php; break;
case "articles" : require_once article_type_show.php; break;
case "classes" : require_once class_type_show.php; break;
case "download" : require_once down_type_show.php; break;
}
或者说:
if(ture) { require_once news_list.php; }
当某个条件成立时包含某个特定的文件.
这样的文件包含效果,asp中可以实现吗?怎么实现呢?
在前面那贴中nnigou(泥垢)朋友说:
那样不可以的
可以用 <script src= "****.asp " > </script >方式写在if里面
我试了一下,还是不行,好像被包含的文件被asp当成文本输出了,或者说是当成客户端脚本了,知道的朋友烦麻给说说
· 网友精彩回答:
直接在select case或if之后写要包含的文件就行了。
如:
文件:a.asp
<%response.write("in a.")%>
文件:b.asp
<%response.write("in b.")%>
在c.asp中根据条件引用:
<%
dim se
se=second(now())
if se mod 2 =1 then
%>
<%=se%><br>
<!--#include file="a.asp"-->
<%else%>
<%=se%><br>
<!--#include file="b.asp"-->
<%end if%>
就这样了。
在asp3.0中
if condition = true then
server.execute "file1.asp"
else
server.execute "file2.asp"
end if
function include(filename)
dim re,content,fso,f,aspstart,aspend
set fso=createobject("scripting.filesystemobject")
set f=fso.opentextfile(server.mappath(filename))
content=f.readall
f.close
set f=nothing
set fso=nothing
set re=new regexp
re.pattern="^\s*="
aspend=1
aspstart=instr(aspend,content,"<%")+2
do while aspstart>aspend+1
response.write mid(content,aspend,aspstart-aspend-2)
aspend=instr(aspstart,content,"%\>")+2
execute(re.replace(mid(content,aspstart,aspend-aspstart-2),"response.write "))
aspstart=instr(aspend,content,"<%")+2
loop
response.write mid(content,aspend)
set re=nothing
end function
使用范例:
include("youinc.asp")
[以上代码摘自互联网,请楼主实验]
- 更多问题:
- · 关于打印发票问题
- · DataGrid数据显示控件显示刷新的问题!希望大家能够帮忙!(分数少,望大家见谅)!
- · 最简单的查询.dbf数据库中对应记录的方法是什么?
- · 最简单的查询.dbf数据库中对应记录的方法是什么?
- · 在知大家用不用BT,请问在BT下了快100%时不能下了!怎么办?好几次,好郁闷啊!~
- · 2003的系统怎么ASP运行会那么慢,求助
- · 关于用c++ builder 打印发票问题???
- · 请问我用了(CTreeCtrl)DeleteAllItems后再加入新的项为何没有显示,但如用MoveWindow后就有了?谢谢!!!
- · 【求教】某人的msn space设了权限偶看不了,有什么办法不?
- · 如何暂停并稍后继续一个线程的执行
- · 最简单的查询.dbf数据库中对应的记录的方法是什么?
- · 不执行 Form1_Load 过程的问题
- · 悬红:如果您是TAPI或者电话编程高手,请以您的工作成果来换取您的报酬
- · 求贤,工作地点北京
- · 看完了C#入门经典和C#技术揭秘,可不可以看一些.Net构架方面的书了
- · 请问神笔电脑书法大师,是用Authorware做的吗?

