论坛: 网站建设 标题: 带参数的标签与模版问题(模版中的标签替换问题) 复制本贴地址    
作者: cgx [cgx]    论坛用户   登录
我把标签替换了,可是结果却在html代码前。
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
</HEAD>

<BODY>

<TABLE cellspacing="0" cellpadding="1" bgcolor="#cccccc" align="center" width="800">
<TR bgcolor="ffffff">
<TD align="center" width="%100">作者:{author(10,3)}</TD>
</TR>
</TABLE>
</BODY>
</HTML>
上面是模版表的模版字段。
主要是{author(10,3)}要替换掉。
替换的代码为:
1、取出模版
<%
set rs=Server.CreateObject("adodb.recordset")
sql="select * from moban where flag=0"
rs.Open sql,conn,1,1
moban=rs("moban")
rs.Close
set rs=Nothing
%>
2、
Sub indextemp()
Call canshubq("{author")//调用函数处理标签。
response.write(""&moban&"")
End Sub
3、处理标签的函数
sub canshubq(lable)
dim tmp1,tmp2,tmpstr,canshu
tmp2=1
while instr(tmp2,moban,lable)>0
tmp1=instr(tmp2,moban,lable)'标签第一位
tmp2=instr(tmp1+1,moban,"}")'标签结束.
tmpstr=mid(moban,tmp1,tmp2-tmp1)'标签除}部分.
tmpstr=replace(tmpstr,lable,"")'去除{author,即剩下参数(10,6)
tmpstr=replace(tmpstr,"(","")
tmpstr=replace(tmpstr,")","")'只剩下10,6
canshu=split(tmpstr,",")
select case lable
case "{author"
moban=replace(moban,lable&"("&tmpstr&")}",author(canshu(0),canshu(1)))
if err then
response.write ("标签错误")
response.end
end if
end select
wend
end sub
4、处理author的函数
function author(a,b)

Set rs=server.CreateObject("adodb.recordset")
sql="select * from news order by id desc"
rs.Open sql,conn,1,1
author=response.write ("<table width=""80%"" bgcolor=""#ff0000"">")
for i=1 to b
if a<>0 then
author3=Left(rs("author"),a)
else
author3=rs("author")
end if
title=rs("title")
content=rs("content")
author2=response.write ("<tr bgcolor=""#ffffff""><td>")
author2=author2&response.write (""&author3&"")
author2=author2&response.write ("</td></tr>")
rs.movenext
next
author=author2&response.Write ("</table>")
rs.close
End function

结果显示出来,我看原代码,是先输出author(a,b)部分,然后才是html代码。这时
模版的代码<TD align="center" width="%100">作者:{author(10,3)}</TD>就变成<TD align="center" width="%100">作者:</TD>了。
具体替换出来后页面代码为:
<table>
<tr><td>作者1</td></tr>
<tr><td>作者2</td></tr>
<tr><td>作者3</td></tr>
………………
</table>
<html>
<head>
</head>
<body>
<TABLE cellspacing="0" cellpadding="1" bgcolor="#cccccc" align="center" width="800">
<TR bgcolor="ffffff">
<TD align="center" width="%100">作者:</TD>
</TR>
</TABLE>
</BODY>
</HTML>

<table>在《html》标签前了。

地主 发表时间: 07-03-26 17:03

回复: NetFog [q70213526]   版主   登录
你闷着脑子写出来的东西吧.看得我头晕

问题出在author这个function中.这个function中请不要用Response.Write输出..

author中的字符及参数连接好后.在过程canshubq中使用Response.Write输出.

才两个sub和一个function就乱成这样了.大型项目的时候.有你受的.呵呵.





B1层 发表时间: 07-03-26 19:23

回复: cgx [cgx]   论坛用户   登录
谢谢,先测试下。以前少写函数.所以有点不懂写.
这个是测试用的。所以可能就有点乱了。

B2层 发表时间: 07-03-27 11:31

回复: cgx [cgx]   论坛用户   登录
搞定了,谢谢。

B3层 发表时间: 07-03-27 14:03

论坛: 网站建设

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号