ASP vbscript过程(函数)中加入HTML格式的代码,如何改为vbscript格式?
将以下代码加入vbscript过程(函数)中,即<%……%>中。问:改用vbscript格式,有什么简洁的写法?<SCRIPTlanguage=javascript>fu...
将以下代码加入vbscript过程(函数)中,即<%……%>中。
问:改用vbscript格式,有什么简洁的写法?
<SCRIPT language=javascript>
function opencat(cat,img){
if(cat.style.display=="none"){
cat.style.display="";
img.src="images/class2.gif";
} else {
cat.style.display="none";
img.src="images/class1.gif";
}
}
</Script>
<TABLE cellSpacing=0 cellPadding=5 width="99%" border=0>
<%
dim i
if rsBigClass.eof and rsBigClass.bof then
Response.Write "栏目正在建设中……"
else
i=1
do while not rsBigClass.eof
%>
<TR>
<TD language=javascript onmouseup="opencat(cat10<%=i%>000,img10<%=i%>000);" id=item$pval[catID]) style="CURSOR: hand" width=32 height=24 align=center>
<IMG id=img10<%=i%>000 src="images/class1.gif" width=20 height=20>
</TD>
<TD width="162"><a href='Pro.asp?BigClassName=<%=rsBigClass("BigClassName")%>'><%=rsBigClass("BigClassPic")%></a></TD>
</TR>
<TR>
<% if BigClassName<>rsBigClass("BigClassName") then %>
<TD id=cat10<%=i%>000 style="DISPLAY" colspan="2">
<% else %>
<TD id=cat10<%=i%>000 style="DISPLAY" colspan="2">
<% end if %>
<%
dim rss,sqls,j
set rss = server.CreateObject ("adodb.recordset")
sqls="select * from SmallClass where BigClassName='" & rsBigClass("BigClassName") & "' order by SmallClassID"
rss.open sqls,conn,1,1
if rss.eof and rss.bof then
Response.Write "没有小分类"
else
j=1
do while not rss.eof
%>
<IMG src="images/class3.gif" height=13 width=13 align=absMiddle border=0> <a href="Pro.asp?BigClassName=<%=rss("BigClassName")%>&Smallclassname=<%=rss("SmallClassName")%>"><%=rss("SmallClassName")%></a><BR>
<%
rss.movenext
j=j+1
loop
end if
rss.close
set rss=nothing
%>
</TD>
</TR>
<%
rsBigClass.movenext
i=i+1
loop
end if
%>
</TABLE>
&
非常感谢 362366724的回答。
你提供的答案能够使程序正常运行。
由于需要模板化。所以要将以上代码改成过程/函数:即放入Sub……end sub中
如果每行HTML代码前都使用Response.Write。文件会膨胀得很大。
不知还有没有更简洁的写法呢?
谢谢! 展开
问:改用vbscript格式,有什么简洁的写法?
<SCRIPT language=javascript>
function opencat(cat,img){
if(cat.style.display=="none"){
cat.style.display="";
img.src="images/class2.gif";
} else {
cat.style.display="none";
img.src="images/class1.gif";
}
}
</Script>
<TABLE cellSpacing=0 cellPadding=5 width="99%" border=0>
<%
dim i
if rsBigClass.eof and rsBigClass.bof then
Response.Write "栏目正在建设中……"
else
i=1
do while not rsBigClass.eof
%>
<TR>
<TD language=javascript onmouseup="opencat(cat10<%=i%>000,img10<%=i%>000);" id=item$pval[catID]) style="CURSOR: hand" width=32 height=24 align=center>
<IMG id=img10<%=i%>000 src="images/class1.gif" width=20 height=20>
</TD>
<TD width="162"><a href='Pro.asp?BigClassName=<%=rsBigClass("BigClassName")%>'><%=rsBigClass("BigClassPic")%></a></TD>
</TR>
<TR>
<% if BigClassName<>rsBigClass("BigClassName") then %>
<TD id=cat10<%=i%>000 style="DISPLAY" colspan="2">
<% else %>
<TD id=cat10<%=i%>000 style="DISPLAY" colspan="2">
<% end if %>
<%
dim rss,sqls,j
set rss = server.CreateObject ("adodb.recordset")
sqls="select * from SmallClass where BigClassName='" & rsBigClass("BigClassName") & "' order by SmallClassID"
rss.open sqls,conn,1,1
if rss.eof and rss.bof then
Response.Write "没有小分类"
else
j=1
do while not rss.eof
%>
<IMG src="images/class3.gif" height=13 width=13 align=absMiddle border=0> <a href="Pro.asp?BigClassName=<%=rss("BigClassName")%>&Smallclassname=<%=rss("SmallClassName")%>"><%=rss("SmallClassName")%></a><BR>
<%
rss.movenext
j=j+1
loop
end if
rss.close
set rss=nothing
%>
</TD>
</TR>
<%
rsBigClass.movenext
i=i+1
loop
end if
%>
</TABLE>
&
非常感谢 362366724的回答。
你提供的答案能够使程序正常运行。
由于需要模板化。所以要将以上代码改成过程/函数:即放入Sub……end sub中
如果每行HTML代码前都使用Response.Write。文件会膨胀得很大。
不知还有没有更简洁的写法呢?
谢谢! 展开
展开全部
改写有很多种方式,直接复制下面的,我已经改写好了,祝你成功!
楼主你好,如果加入sub过程的话,也很简单,代码如下
调用的时候直接说<%=xxxx()%>或者<%Response.write xxxx()%>
你放心,国内的知名CMS系统都是用的这种写法,既能够提高速度,还能提升ASP整体性能,你想想,服务器一直处理ASP,总比处理一句ASP马上换成出来一句HMTL语句好得多,在这个转换过程中,ASP绝对是提升性能力的,丝毫没有影响你的速度,代码的话,就算你用原来的可能是2KB,而现在最多3KB,只是多了一写输出语句而已,如果用Response.write"doctment.write('<table>....')"的话,是一种写法,但是代码还要多,而且还要从Asp转到javascript然后换成Html输出客户端,所以中和一下,下面的是最好的!调用也很简单,但是确保你调用的页面必须包含conn.asp文件,因为你下面建立了实例对象Rs.
<% '这里定义一个名为xxxx的sub过程
Sub xxxx()
'改写有多种方式,我现在用每行换行+Vbcrlf格式的给你写,因为他的速度最快
Response.Write "<SCRIPT language=javascript>" & vbCrLF
Response.Write " function opencat(cat,img){" & vbCrLF
Response.Write " if(cat.style.display=='none'){" & vbCrLF
Response.Write " cat.style.display='';" & vbCrLF
Response.Write " img.src='images/class2.gif';" & vbCrLF
Response.Write " } else {" & vbCrLF
Response.Write " cat.style.display='none'; " & vbCrLF
Response.Write " img.src='images/class1.gif';" & vbCrLF
Response.Write " }" & vbCrLF
Response.Write "}" & vbCrLF
Response.Write "</Script>" & vbCrLF
Response.Write "<TABLE cellSpacing='0' cellPadding='5' width='99%' border='0'>" & vbCrLF
Dim i
If rsBigClass.eof and rsBigClass.bof then
Response.Write "栏目正在建设中……"
else
i=1
do while not rsBigClass.eof
Response.Write " <TR>" & vbCrLF
Response.Write "<TD language=javascript onmouseup='opencat(cat10"&i&"000,img10"&i&"000);' id=item$pval[catID]) style='CURSOR: hand' width='32' height='24' align='center'>" & vbCrLF
Response.Write " <IMG id=img10"&i&"000 src='images/class1.gif' width='20' height='20'>" & vbCrLF
Response.Write "</TD>" & vbCrLF
Response.Write "<TD width='162'><a href='Pro.asp?BigClassName="&rsBigClass("BigClassName")&"'>"&rsBigClass("BigClassPic")&"</a></TD>" & vbCrLF
Response.Write " </TR>" & vbCrLF
Response.Write " <TR>" & vbCrLF
If BigClassName<>rsBigClass("BigClassName") then
Response.Write " <TD id=cat10" & i & "000 style=""DISPLAY"" colspan=2>" & vbCrLF
Else
Response.Write " <TD id=cat10" & i & "000 style='DISPLAY' colspan='2'>" & vbCrLF
End if
Dim rss,sqls,j
Set rss = server.CreateObject ("adodb.recordset")
sqls="select * from SmallClass where BigClassName='" & rsBigClass("BigClassName") & "' order by SmallClassID"
rss.open sqls,conn,1,1
If rss.Eof and rss.Bof then
Response.Write "没有小分类"
Else
j=1
Do while not rss.Eof
Response.Write "<IMG src='images/class3.gif' height='13' width='13' align='absMiddle' border='0'> <a href='Pro.asp?BigClassName="& rss("BigClassName") &"&Smallclassname="& rss("SmallClassName")&"'>"&rss("SmallClassName") & "</a><BR>" & vbCrLF
rss.movenext
j=j+1
loop
end if
rss.close
set rss=nothing
Response.Write " </TD>" & vbCrLF
Response.Write "</TR>" & vbCrLF
rsBigClass.movenext
i=i+1
loop
end if
Response.Write "</TABLE> " & vbCrLF
End sub
%>
楼主你好,如果加入sub过程的话,也很简单,代码如下
调用的时候直接说<%=xxxx()%>或者<%Response.write xxxx()%>
你放心,国内的知名CMS系统都是用的这种写法,既能够提高速度,还能提升ASP整体性能,你想想,服务器一直处理ASP,总比处理一句ASP马上换成出来一句HMTL语句好得多,在这个转换过程中,ASP绝对是提升性能力的,丝毫没有影响你的速度,代码的话,就算你用原来的可能是2KB,而现在最多3KB,只是多了一写输出语句而已,如果用Response.write"doctment.write('<table>....')"的话,是一种写法,但是代码还要多,而且还要从Asp转到javascript然后换成Html输出客户端,所以中和一下,下面的是最好的!调用也很简单,但是确保你调用的页面必须包含conn.asp文件,因为你下面建立了实例对象Rs.
<% '这里定义一个名为xxxx的sub过程
Sub xxxx()
'改写有多种方式,我现在用每行换行+Vbcrlf格式的给你写,因为他的速度最快
Response.Write "<SCRIPT language=javascript>" & vbCrLF
Response.Write " function opencat(cat,img){" & vbCrLF
Response.Write " if(cat.style.display=='none'){" & vbCrLF
Response.Write " cat.style.display='';" & vbCrLF
Response.Write " img.src='images/class2.gif';" & vbCrLF
Response.Write " } else {" & vbCrLF
Response.Write " cat.style.display='none'; " & vbCrLF
Response.Write " img.src='images/class1.gif';" & vbCrLF
Response.Write " }" & vbCrLF
Response.Write "}" & vbCrLF
Response.Write "</Script>" & vbCrLF
Response.Write "<TABLE cellSpacing='0' cellPadding='5' width='99%' border='0'>" & vbCrLF
Dim i
If rsBigClass.eof and rsBigClass.bof then
Response.Write "栏目正在建设中……"
else
i=1
do while not rsBigClass.eof
Response.Write " <TR>" & vbCrLF
Response.Write "<TD language=javascript onmouseup='opencat(cat10"&i&"000,img10"&i&"000);' id=item$pval[catID]) style='CURSOR: hand' width='32' height='24' align='center'>" & vbCrLF
Response.Write " <IMG id=img10"&i&"000 src='images/class1.gif' width='20' height='20'>" & vbCrLF
Response.Write "</TD>" & vbCrLF
Response.Write "<TD width='162'><a href='Pro.asp?BigClassName="&rsBigClass("BigClassName")&"'>"&rsBigClass("BigClassPic")&"</a></TD>" & vbCrLF
Response.Write " </TR>" & vbCrLF
Response.Write " <TR>" & vbCrLF
If BigClassName<>rsBigClass("BigClassName") then
Response.Write " <TD id=cat10" & i & "000 style=""DISPLAY"" colspan=2>" & vbCrLF
Else
Response.Write " <TD id=cat10" & i & "000 style='DISPLAY' colspan='2'>" & vbCrLF
End if
Dim rss,sqls,j
Set rss = server.CreateObject ("adodb.recordset")
sqls="select * from SmallClass where BigClassName='" & rsBigClass("BigClassName") & "' order by SmallClassID"
rss.open sqls,conn,1,1
If rss.Eof and rss.Bof then
Response.Write "没有小分类"
Else
j=1
Do while not rss.Eof
Response.Write "<IMG src='images/class3.gif' height='13' width='13' align='absMiddle' border='0'> <a href='Pro.asp?BigClassName="& rss("BigClassName") &"&Smallclassname="& rss("SmallClassName")&"'>"&rss("SmallClassName") & "</a><BR>" & vbCrLF
rss.movenext
j=j+1
loop
end if
rss.close
set rss=nothing
Response.Write " </TD>" & vbCrLF
Response.Write "</TR>" & vbCrLF
rsBigClass.movenext
i=i+1
loop
end if
Response.Write "</TABLE> " & vbCrLF
End sub
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询