下面是动态生成列表,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.   

    这不是jsp的问题。把window.去掉。
      

  2.   

    我显示了一个window.total,一个total
    都显示为undefined
      

  3.   

    我如果再asp文件中的var total;下面再加一句total=0;
    在函数中total就会显示为0,而total=<% =count %>;根本没起作用,但是在浏览器中查看
    源文件可以看到total=11
      

  4.   

    看看这个 http://www.haolla.com/girls/index.asp
      

  5.   

    subcat[<% =count %>]=new array("<% =rst(1) %>","<% =rst(2) %>");
    这句去掉也能正常