首页 > 程序开发 > web前端 > JavaScript >

实例演示:jsp+javascript打造级连菜单

2008-05-21

  <%@ page import="java.util.Date,yava.fileapp.*,java.sql.*;"         contentType="text/html;charset=GB2312" pageEncoding="GB2312"  %>  <style>  .f9

<%@ page import="java.util.Date,yava.fileapp.*,java.sql.*;"
contentType="text/html;charset=GB2312" pageEncoding="GB2312"
%>
<style>
.f9&#123; font-size:9pt; &#125;
.bgc&#123; background-color:#AECAF9; color: #0033FF &#125;
.buttons&#123;font-family:Arial; font-size:13px; font-weight:bold; background-color:#6796E4; color:white; border-top: solid 2px #AACAFB;
border-bottom: solid 1px #4E7DC1;
border-left: solid 1px #AECAF9;
border-right: solid 1px #5679BD;
padding:1px;
margin:0px;&#125;
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function rv()
&#123;
var val="";
for(i=0;i<combo_box.list2.length;i++)&#123;
val+=","+combo_box.list2[i].value;
&#125;
if(val.charAt(0)==",")&#123;
val=val.substr(1,val.length);
&#125;
opener.form1.frecname.value=val;
self.close();
&#125;

//-->
</SCRIPT>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<jsp(SUN企业级应用的首选):useBean id="user" scope="session" class="yava.fileapp.UserBean" />
<%
CDataSource ds=new CDataSource(); //数据联结Bean实例
java.sql.Connection conn=ds.getConnection();
java.sql.Statement stmt=null;
java.sql.ResultSet rs=null;
CDataCheck dc=new CDataCheck();
%>

<%
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())
&#123;
%>
arr[<%=temp%>]=new Array("<%=rs.getString("fname")%>","<%=rs.getString("fdept")%>");
<%
temp = temp + 1;
&#125;
%>
temp=<%=temp%>;
function ChangeLocation(id)&#123;
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++)&#123;
if(arr[i][1]==id)&#123;//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
document.combo_box.city.options[document.combo_box.city.length] = new Option(arr[i][0], arr[i][0]);
&#125;
&#125;
&#125;
</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>

相关文章
最新文章
热点推荐