请问如何生成广告的js文件

fwy12 2011-04-27 12:53:51
我的网站中有广告,有id,content。ID是广告的id,content是广告的内容代码,请问如何用asp将广告的内容content代码生成js文件呢。id为1的就生成1.JS,id为2的就生成2.JS,就是说id位几的就生成几.js。可以点击一个连接全部生成,也可以一个一个的生成。
...全文
125 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fwy12 2011-04-29
  • 打赏
  • 举报
回复
恩,多谢楼上的兄弟指点,我明白了。
fwy12 2011-04-28
  • 打赏
  • 举报
回复
<%sid=request("id")%><%  
set js = server.CreateObject("ADODB.RecordSet")
sql="select * from "&tbname&"_ad where id="& sid &" "
set js = conn.Execute (Sql)
do while not js.eof
content=js("content")
foolcat = foolcat + "<li>" &content&" </li><br>"
js.movenext
loop
'生成JS文件
foolcat = "" + foolcat + ""
foolcat = "document.write('" & foolcat & "')"
FolderPath = Server.MapPath("../ad")
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(FolderPath&"\"& sid &" .js")
fout.WriteLine foolcat
'关闭连接
fout.close
set fout = nothing
js.close
set js = nothing

Call Info("广告" & sid & ".js已生成!")
%>


我的生成代码是这样的请问如何写才能让他一次性将数据库中的所有记录都生成的,如有10条记录,就生成10个js文件。
fwy12 2011-04-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hongmei85 的回复:]
http://hi.baidu.com/lz0830/blog/item/adab27ce4c06010593457e3e.html
[/Quote]

这个我早就看过了,是生成HTML的办法,不是生成js的办法。
lzp4881 2011-04-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 fwy12 的回复:]
多谢楼上的兄弟批评,一定的更加勤奋的学习。

同时请问一下sql = "select * from "&tbname&"_ad where 1 = 1 ",where 1= 1是什么意思。
[/Quote]
实际上就相当于
sql="select * from tbname"
之所以加上where 1=1,是便于在后面再加条件
fwy12 2011-04-28
  • 打赏
  • 举报
回复
多谢楼上的兄弟批评,一定的更加勤奋的学习。

同时请问一下sql = "select * from "&tbname&"_ad where 1 = 1 ",where 1= 1是什么意思。
ChinaXtHuLang 2011-04-28
  • 打赏
  • 举报
回复
很久没有来asp专区了。刚一上来就看到无聊的。。
第一。生成html方法和js有什么不一样吗??不就是扩展名不一样。。
html通过模版得到。通过模版得到的同时难道不需要用变量赋值

生成js直接用变量也是一样

另外。你以前发的好几个帖子都是生成html的。。看你这几个月了,一点进步也没。。
真不想发这贴的。

<%
Dim foolcat
foolcat = ""
FolderPath = Server.MapPath("../ad")
sid = request("id")
Set js = server.CreateObject("ADODB.RecordSet")
sql = "select * from "&tbname&"_ad where 1 = 1 "
If sid <> "" Then
Sql = Sql & " And id="& sid &" "
End If
Set js = conn.Execute (Sql)
Do While Not js.EOF


foolcat = foolcat & "<li>" &js("content")&" </li><br>"
foolcat = foolcat & "document.write('" & foolcat & "')"
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(FolderPath&"\"& js("id") &" .js")
fout.WriteLine foolcat
'关闭连接
fout.Close
Set fout = Nothing

Call Info("广告" & js("id") & ".js已生成!")
js.movenext
Loop
'生成JS文件
js.Close
Set js = Nothing
%>

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧