用asp产生select下拉列表后,在客户浏览器中用javascript对其进行排序,这段排序程序却不起作用不知什么原因

zqshan 2001-03-14 09:40:00

请看下面的asp页面文件,其中javascript只循环了5次,产生的select代码改为其它的也一样,如果在设计时静态加入select列表中,那么,那段javascript就会正常执行,不信可以试一试,如果哪位知道原因望知之
___________________________________________________________________

<%@ Language=VBScript %>
<%Response.Expires =0 %>
<!--#INCLUDE FILE="share/conn.asp"-->
<html>
<head>
<title>test</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<select name="category_name" >
<%
function getNodePath(p_id)
dim rs,sqlstr,id,str
id=p_id
getpath=""
str=""
set rs=server.createobject("adodb.recordset")
do while true
sqlstr="select product.name,product_bom.* from product,product_bom " & _
"where product_bom.subdep_id=" & id & " and product_bom.subdep_id=product.id"
set rs = conn.Execute (sqlstr)
if rs.eof then exit do
str= "\" & rs("name") & str
if rs("dep_id")=1 then exit do
id=rs("dep_id")
rs.close
loop
rs.close
set rs=nothing

getNodePath=str
end function

dim rs,rscnt,sql,sqlcnt,str
str=""
set rs=createobject("adodb.recordset")
set rscnt=createobject("adodb.recordset")
sql="select product_bom.subdep_id from product,product_bom " & _
"where product_bom.subdep_id=product.id " & _
" and product.price is null"
rs.open sql,conn
do while not rs.eof
sqlcnt="select count(*) as p_count from product,product_bom where dep_id=" & _
rs("subdep_id") & " and product.id=product_bom.subdep_id and product.price is null"
rscnt.open sqlcnt,conn
if rscnt("p_count")=0 then
%>
<option value=<%=rs("subdep_id")%>><%=getNodePath(rs("subdep_id"))%></option>
<%
end if
rscnt.close
rs.movenext
loop
set rscnt=nothing
rs.close
set rs=nothing
%>
</select>
</form>
<script language="JavaScript">
function category_sort()
{
var items=document.all("select").options;
var i,j,temp;
document.write("items.length="+items.length+"<br>");
for(i=0;i<items.length-1;i++)
{
for(j=i+1;j<items.length;j++)
{

if(items[i].text>items[j].text)
{

temp=items[i].value;
items[i].value=items[j].value;
items[j].value=temp;

temp=items[i].text;
items[i].text=items[j].text;
items[j].text=temp;
}
}
}
}
category_name(();
</script>
</p>
</body>
</html>
...全文
121 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
supersonics 2001-03-14
  • 打赏
  • 举报
回复
一般来说,别人是不会有兴趣看你的大段代码的,大多是把你的代码往哪里一贴,开始debug。
如果你贴出的是html,debug好一点;如果是asp,由于不具备数据库环境,所以比较难debug.当然,那位热心的大哥愿意自建数据库或手上有类似代码的例外。
所以,建议你贴出html来;再说,你这个问题从html上应该就可以看出来了。
-------------------------------------------------------------------
以上纯属个人观点,如有冒犯,还请海涵。
sdtashenjie 2001-03-14
  • 打赏
  • 举报
回复
下面例子请参考:
function to_up() {
document.all("button4").disabled=false;
loca=document.a_frm.select1.selectedIndex;
if (loca>1) {
opt0 = new Option;
opt1 = new Option;
opt0.value = document.a_frm.select1.options[document.a_frm.select1.selectedIndex-1].value;
opt0.text = document.a_frm.select1.options[document.a_frm.select1.selectedIndex-1].text;
opt1.value = document.a_frm.select1.options[document.a_frm.select1.selectedIndex].value;
opt1.text = document.a_frm.select1.options[document.a_frm.select1.selectedIndex].text;
document.a_frm.select1.options[document.a_frm.select1.selectedIndex-1]=opt1;
document.a_frm.select1.options[document.a_frm.select1.selectedIndex]=opt0;
document.a_frm.select1.selectedIndex=loca-1;
if (document.all("select1").selectedIndex==1) document.all("button3").disabled=true;
}
}
zqshan 2001-03-14
  • 打赏
  • 举报
回复
对不起,category_name(();多了一个括号
dhwan 2001-03-14
  • 打赏
  • 举报
回复
这是什么意思:category_name(();
你的函数名不是category_sort吗?

28,405

社区成员

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

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