正在阅读:实例演示:jsp+javascript打造级连菜单实例演示:jsp+javascript打造级连菜单

2004-02-14 09:34 出处:CSDN 作者:xhbmj 责任编辑:linjixiong

  <%
   String sqlu="SELECT t1.fno, t1.fname, t2.fname AS fdept FROM tuser t1 LEFT OUTER JOIN TDept t2 ON t1.fdept = t2.fno order by t2.fname";
   stmt=conn.createStatement();
   rs=stmt.executeQuery(sqlu);
  %>
   <script language='Javascript'>
   arr = new Array();
  <%  int temp=0;
   while(rs.next())
   {
  %>
   arr[<%=temp%>]=new Array("<%=rs.getString("fname")%>","<%=rs.getString("fdept")%>");
  <%
   temp = temp + 1;
   }
  %>
  temp=<%=temp%>;
  function ChangeLocation(id){
  document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
  var i = 0;
  document.combo_box.city.options[0]=new Option('-------','');
  for(i=0;i<temp;i++){
  if(arr[i][1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
  document.combo_box.city.options[document.combo_box.city.length] = new Option(arr[i][0], arr[i][0]);
  }
  }
  }
  </script>

  <form name="combo_box">
  <table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
  <tr height="24">
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
  </tr>

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品