代码功能:实现提取每个栏目文章的头几条显示出来。
asp代码写好好执行的很正常,想写成以js的形式重复调用这部分代码。
写成如下js后,用<script src=".asp">的形式嵌入到asp网页中却不显示结果。不知是什么原因。请各位帮忙。代码如下:
<!--#include file="inc/conn.asp"-->
<% 
bigclassID=request("ClassID")
num = request("number")
num2=request("number2")
if num="" then num=10
if num2="" then num2=40if bigclassID="" then 
response.Redirect("ErrorPage.asp")
end if
if bigclassID<>"" then
Set rs_class=Server.CreateObject("Adodb.RecordSet")
rs_class.Open "Select * from BigClass"&"l_j"&"New where BigClassID=" & CLng(bigclassID),conn,1,3
if rs_class.Bof and rs_class.EOF then
FoundErr=True
ErrMsg=ErrMsg & "<br><li>此栏目不存在!</li>"
else
    bigclass=rs_class("BigClassName")
end if
rs_class.close
set rs_class=nothing
end if%>
document.write("<table height=100% border='0' width='95%' align='center' id='table1'>")
            <% 
Set rs=Server.CreateObject("ADODB.RecordSet") 
sql="select top "& num &" * from news where BigClassName='"&bigclass&"' order by ding desc,id desc"
rs.Open sql,conn,1,1
if rs.eof and rs.bof then
  response.Write("暂时没有记录")
else 
for j=1 to num 
title=rs("title")
id=rs("id")
ok=rs("ok")
a=num2
a=a-1
main_title = gotTopic(title,a)
if ok = true then 
a=a-4
end if
main_title = gotTopic(title,a)
%>
document.write("<tr valign=top>")
document.write("<td height='24' width=100% style='border-bottom: 1px dotted #cccccc;'>")
document.write("<a title='<%=title %>' target='_blank' class='main_text' href='Article_Show.asp?ArticleID=<%=id %>'>")
<%if bigclassID=2 then %>document.write("<img src='image/ico3.gif' border=0 />")<%else %>document.write("<img src='image/ico4.gif' border=0 />")<%end if%>document.write("<%=main_title%></a>&nbsp;  ")<% if ok=true then %>document.write("<img src='image/new.gif' border=0 alt='最新新闻'>")<% end if %>document.write("</td></tr>")
                <%
rs.movenext
if rs.eof then exit for
next
end if
rs.close
set rs=nothing
%>
document.write("</table> ")

解决方案 »

  1.   

    document.write()后面要加;
    document.write();另外,看浏览器里面 的源代码看是否符合js语法
      

  2.   

    <%%>中间是服务器代码,在js文件中不支持这样的写法
    因为<%%>里面的服务器代码是在服务器生成页面html代码时执行的,html代码生成后发送到页面.
    而js文件是浏览器已经获取html代码后输出时根据src地址从后台获取,此时不会执行后台代码,所以<%%>这种写法在js文件中不被支持.
      

  3.   

    document.write()后面加;
    后也还是不行我看网上开源的文件都是这么写的,为什么我写的就不行呢
      

  4.   

    document.write()加;后也还是不行 别的开源代码都这么写都没问题,为什么我的就不执行呢。
      

  5.   

    本帖最后由 net_lover 于 2012-08-25 13:44:52 编辑