下面是动态生成列表,class表包括字段
编号,大类,小类
如 1,电脑,联想这是asp文件
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../Include/conn.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<body>
<%
dim count
strsql="select * from class order by 大类,小类"
set rst=con.execute(strsql)
%>
<script language="JavaScript">
var total;
subcat=new array();
<% count=0
do while not rst.eof %>
subcat[<% =count %>]=new array("<% =rst(1) %>","<% =rst(2) %>");
<% count=count+1
rst.movenext
loop
rst.close %>
total=<% =count %>;
function changes(ee)
{ alert('a ' + window.total);
alert('a ' + ee);
document.myform.nd2.lenght=0;
alert('b ' + total);
}
changes("ee")
</script>
<form action="" method="post" name="myform" id="myform">
<table width="200" border="0" align="center">
<tr>
<td>大类</td>
<td><% rst.open "select distinct 大类 from class order by 大类",con,1,1
if rst.eof then
response.write "请先添加大类。"
response.end
else %>
<select name="st1" onchange="changes(this.value)">
<option selected value="<% =rst(0) %>">
<% =rst(0) %>
</option>
<%
nd2v=rst(0)
rst.movenext
do while not rst.eof %>
<option value="<% =rst(0) %>">
<% =rst(0) %>
</option>
<% rst.movenext
loop
end if
rst.close %>
</select>
</td>
</tr>
<tr>
<td>小类</td>
<td><select name="nd2">
<%
strsql="select 小类 from class where 大类='" & nd2v & "'"
rst.open strsql,con,1,1
do while not rst.eof %>
<option value="<% =rst(0) %>">
<% =rst(0) %>
</option>
<% rst.movenext
loop
rst.close %>
</select></td>
</tr>
</table>
</form>
</body>
</html>
******************************************************
以下是asp文件生成的结果(用查看源文件)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<body><script language="JavaScript">
var total;
subcat=new array();
subcat[0]=new array("笔记本","宏基");
subcat[1]=new array("笔记本","华硕");
subcat[2]=new array("电脑","方正");
subcat[3]=new array("电脑","惠普");
subcat[4]=new array("电脑","联想");
subcat[5]=new array("图书","法律");
subcat[6]=new array("图书","教育");
subcat[7]=new array("图书","科技");
subcat[8]=new array("图书","历史");
subcat[9]=new array("图书","战争");
subcat[10]=new array("图书","政治");
total=11;
function changes(ee)
{ alert('a ' + window.total);
alert('a ' + ee);
document.myform.nd2.lenght=0;
alert('b ' + total);
}
changes("ee")
</script>
<form action="" method="post" name="myform" id="myform">
<table width="200" border="0" align="center">
<tr>
<td>大类</td>
<td>
<select name="st1" onchange="changes(this.value)">
<option selected value="笔记本">
笔记本
</option>
<option value="电脑">
电脑
</option>
<option value="图书">
图书
</option>
</select>
</td>
</tr>
<tr>
<td>小类</td>
<td><select name="nd2">
<option value="华硕">
华硕
</option>
<option value="宏基">
宏基
</option>
</select></td>
</tr>
</table>
</form>
</body>
</html>
*****************************************
为何在函数中使用tota变量总显示为undefined
编号,大类,小类
如 1,电脑,联想这是asp文件
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../Include/conn.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<body>
<%
dim count
strsql="select * from class order by 大类,小类"
set rst=con.execute(strsql)
%>
<script language="JavaScript">
var total;
subcat=new array();
<% count=0
do while not rst.eof %>
subcat[<% =count %>]=new array("<% =rst(1) %>","<% =rst(2) %>");
<% count=count+1
rst.movenext
loop
rst.close %>
total=<% =count %>;
function changes(ee)
{ alert('a ' + window.total);
alert('a ' + ee);
document.myform.nd2.lenght=0;
alert('b ' + total);
}
changes("ee")
</script>
<form action="" method="post" name="myform" id="myform">
<table width="200" border="0" align="center">
<tr>
<td>大类</td>
<td><% rst.open "select distinct 大类 from class order by 大类",con,1,1
if rst.eof then
response.write "请先添加大类。"
response.end
else %>
<select name="st1" onchange="changes(this.value)">
<option selected value="<% =rst(0) %>">
<% =rst(0) %>
</option>
<%
nd2v=rst(0)
rst.movenext
do while not rst.eof %>
<option value="<% =rst(0) %>">
<% =rst(0) %>
</option>
<% rst.movenext
loop
end if
rst.close %>
</select>
</td>
</tr>
<tr>
<td>小类</td>
<td><select name="nd2">
<%
strsql="select 小类 from class where 大类='" & nd2v & "'"
rst.open strsql,con,1,1
do while not rst.eof %>
<option value="<% =rst(0) %>">
<% =rst(0) %>
</option>
<% rst.movenext
loop
rst.close %>
</select></td>
</tr>
</table>
</form>
</body>
</html>
******************************************************
以下是asp文件生成的结果(用查看源文件)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<body><script language="JavaScript">
var total;
subcat=new array();
subcat[0]=new array("笔记本","宏基");
subcat[1]=new array("笔记本","华硕");
subcat[2]=new array("电脑","方正");
subcat[3]=new array("电脑","惠普");
subcat[4]=new array("电脑","联想");
subcat[5]=new array("图书","法律");
subcat[6]=new array("图书","教育");
subcat[7]=new array("图书","科技");
subcat[8]=new array("图书","历史");
subcat[9]=new array("图书","战争");
subcat[10]=new array("图书","政治");
total=11;
function changes(ee)
{ alert('a ' + window.total);
alert('a ' + ee);
document.myform.nd2.lenght=0;
alert('b ' + total);
}
changes("ee")
</script>
<form action="" method="post" name="myform" id="myform">
<table width="200" border="0" align="center">
<tr>
<td>大类</td>
<td>
<select name="st1" onchange="changes(this.value)">
<option selected value="笔记本">
笔记本
</option>
<option value="电脑">
电脑
</option>
<option value="图书">
图书
</option>
</select>
</td>
</tr>
<tr>
<td>小类</td>
<td><select name="nd2">
<option value="华硕">
华硕
</option>
<option value="宏基">
宏基
</option>
</select></td>
</tr>
</table>
</form>
</body>
</html>
*****************************************
为何在函数中使用tota变量总显示为undefined
解决方案 »
- JSP POST传参为何是ISO8859_1,
- 关于freemarker中取值的问题!
- 新闻动态显示问题
- 关于Apache与SVN的整合
- (在线等待)请教一个关于hibernate的问题:javax.servlet.ServletException: Not able to obtain connection
- jsp如何调用ActiveX
- linux下安装好tomcat之后,JSP默认的主页为什么总是这个?
- HTTP Status 500错误?请教高手
- javaBean的自定义标志
- 怎么回事?我的邮箱收不到帖子了.斑竹.帮我向上面反应,反应.我的消息太闭塞了.
- 请教,TOMCAT配连接池的出现问题
- struts和hibernate一般都用的mySQL作为数据库的,不知道在别的数据库中是不是同样的
都显示为undefined
在函数中total就会显示为0,而total=<% =count %>;根本没起作用,但是在浏览器中查看
源文件可以看到total=11
这句去掉也能正常