jsp+javascript打造级连菜单代码

<%@ page import="java.util.Date,yava.fileapp.*,java.sql.*;"
         contentType="text/html;charset=GB2312" pageEncoding="GB2312"
%>
<style>
.f9{ font-size:9pt; }
.bgc{ background-color:#AECAF9; color: #0033FF }
.buttons{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;}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function rv()
{
  var val="";
  for(i=0;i<combo_box.list2.length;i++){
   val+=","+combo_box.list2[i].value;
  }
  if(val.charAt(0)==","){
   val=val.substr(1,val.length);
  }
  opener.form1.frecname.value=val;
  self.close();
}

//-->
</SCRIPT>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<jsp: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())
 {
%>
 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>
  <tr>
    <td>
  <select multiple id=prov name="prov"  onchange="ChangeLocation(combo_box.prov.options[combo_box.prov.selectedIndex].text);"  style="width:150;height:200" class="bgc">
  <option value="0">请选择部门 ---></option>
<%
    String sqld="SELECT * FROM tdept";
 stmt=conn.createStatement();
 rs=stmt.executeQuery(sqld);
 while(rs.next())
 {
%>
  <option name="<%=rs.getString("fno")%>"><%=rs.getString("fname")%></option>
<%
 }
%>
  </select>
 </td>
    <td>
  <select multiple id=city style="width:150;height:200" class="bgc">
  </select>
 </td>
    <td nowrap align="center" class="bgc">
  <input type="button" onClick="move(this.form.list2,this.form.city)" value="<<" class="buttons">
  <input type="button" onClick="move(this.form.city,this.form.list2)" value=">>" class="buttons">
 </td>
    <td>
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
  </select>
 </td>
  </tr>
    <tr class="bgc">
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" onclick="rv();"></td>
  </tr>
</table>
</form>

<script language="JavaScript">
//人名移动
function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
}
else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
   }
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
   }
}

</script>
</body>

时间: 2024-10-02 05:48:45

jsp+javascript打造级连菜单代码的相关文章

jsp+javascript打造级连菜单的实例代码_javascript技巧

  复制代码 代码如下:   <%@ page import="java.util.Date,yava.fileapp.*,java.sql.*;"         contentType="text/html;charset=GB2312" pageEncoding="GB2312"  %>  <style>  .f9{ font-size:9pt; }  .bgc{ background-color:#AECAF9;

jsp+javascript打造级连菜单

javascript|js|菜单 <%@ page import="java.util.Date,yava.fileapp.*,java.sql.*;"         contentType="text/html;charset=GB2312" pageEncoding="GB2312"%><style>.f9{ font-size:9pt; }.bgc{ background-color:#AECAF9; color:

jsp+&amp;#106avascript打造级连菜单

js|菜单 <%@ page import="java.util.Date,yava.fileapp.*,java.sql.*;"         contentType="text/html;charset=GB2312" pageEncoding="GB2312"%><style>.f9{ font-size:9pt; }.bgc{ background-color:#AECAF9; color: #0033FF }.

ajax 级联动菜单代码

ajax 级联动菜单代码 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>ajax2级联动菜单演示</title> <script language="javascript"> var http_request=false;   functi

JavaScript模拟下拉菜单代码_表单特效

JavaScript模拟下拉菜单,做的仓促,虚心接受批评. 请选择19881989请选择年份 性别男女请选择性别 幼儿班小学初中请选择学历

javascript城市select联动菜单代码

下面这款js城市select联动菜单代码是我从其它网站搞下来的,很好用的,全部所有城市都用了,你只要把js部份保存,然后修select修改成如下面这个select同名就可以使用了. <p><select class="select_com" id="city" style="margin-top: -1px; margin-left: -1px; width: 134px; height: 25px" name="ci

用JSP+JavaScript打造二级级联下拉菜单

class(一级栏目信息):classId(自动编号),className(栏目名称), Nclass(二级栏目信息), NclassId(自动编号),NclassName(栏目名称),parentId(一级栏目id,与class表中的classId关联) <%@ page contentType=text/html; charset=GB2312 language=java errorPage=../error.jsp %><%@ include file=../conn.jsp%&g

Jsp+javascript打造二级级联下拉菜单

javascript|js|菜单|下拉 数据库需求分析: class(一级栏目信息):classId(自动编号),className(栏目名称) Nclass(二级栏目信息):NclassId(自动编号),NclassName(栏目名称),parentId(一级栏目id,与class表中的classId关联) <%@ page contentType="text/html; charset=GB2312" language="java" errorPage=&

jsp/javascript打印九九乘法表代码_JSP编程

jsp表达式方式: 复制代码 代码如下: <center> <table border="1"> <% for (int i = 1; i <= 9; i++) { %> <tr> <% for (int j = 1; j <= 9; j++) { %> <td> <% if (j <= i) { %> <%=i%>*<%=i%>=<%=i * j%>