熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

jsp+javascript打造級連菜單代碼

2013-11-15 12:14:26  來源: JSP教程 

  <%@ page import="javautilDateyavafileapp*javasql*;"
         contentType="text/html;charset=GB" pageEncoding="GB"
%>
<style>
f{ fontsize:pt; }
bgc{ backgroundcolor:#AECAF; color: #FF }
buttons{fontfamily:Arial; fontsize:px; fontweight:bold; backgroundcolor:#E; color:white; bordertop: solid px #AACAFB;
  borderbottom: solid px #EDC;
  borderleft: solid px #AECAF;
  borderright: solid px #BD;
  padding:px;
  margin:px;}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!
function rv()
{
  var val="";
  for(i=;i<combo_boxlistlength;i++){
   val+=""+combo_boxlist[i]value;
  }
  if(valcharAt()==""){
   val=valsubstr(vallength);
  }
  openerformfrecnamevalue=val;
  selfclose();
}

  //>
</SCRIPT>
<body leftmargin="" topmargin="" marginwidth="" marginheight="">
<jsp:useBean id="user" scope="session" class="yavafileappUserBean" />
<%
  CDataSource ds=new CDataSource();  //數據聯結Bean實例
  javasqlConnection conn=dsgetConnection();
  javasqlStatement stmt=null;
  javasqlResultSet rs=null;
  CDataCheck dc=new CDataCheck();
%>

  <%
 String sqlu="SELECT tfno tfname tfname AS fdept FROM tuser t LEFT OUTER JOIN TDept t ON tfdept = tfno order by tfname";
 stmt=conncreateStatement();
 rs=stmtexecuteQuery(sqlu);
%>
 <script language=Javascript>
 arr = new Array();
<%  int temp=;
 while(rsnext())
 {
%>
 arr[<%=temp%>]=new Array("<%=rsgetString("fname")%>""<%=rsgetString("fdept")%>");
<%
 temp = temp + ;
 }
%>
temp=<%=temp%>;
function ChangeLocation(id){
documentcombo_boxcitylength=; //初始化第級菜單的長度下標從開始
var i = ;
documentcombo_boxcityoptions[]=new Option();
for(i=;i<temp;i++){
if(arr[i][]==id){//如果相等證明在第級裡面有輸入第級組織的子集arr[總數目][部門]
documentcombo_boxcityoptions[documentcombo_boxcitylength] = new Option(arr[i][] arr[i][]);
}
}
}
</script>

  
<form name="combo_box">
<table border="" cellspacing="" cellpadding="" height="" width="">
  <tr height="">
    <td bgcolor="#" class="buttons" align=center><font color=#ffffff>部門選擇</font></td>
    <td bgcolor="#" class="buttons" align=center><font color=#ffffff>人名選擇</font></td>
    <td bgcolor="#" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
    <td bgcolor="#" class="buttons" align=center><font color=#ffffff>最終人</font></td>
  </tr>
  <tr>
    <td>
  <select multiple id=prov name="prov"  onchange="ChangeLocation(combo_boxprovoptions[combo_boxprovselectedIndex]text);"  style="width:;height:" class="bgc">
  <option value="">請選擇部門 ></option>
<%
    String sqld="SELECT * FROM tdept";
 stmt=conncreateStatement();
 rs=stmtexecuteQuery(sqld);
 while(rsnext())
 {
%>
  <option name="<%=rsgetString("fno")%>"><%=rsgetString("fname")%></option>
<%
 }
%>
  </select>
 </td>
    <td>
  <select multiple id=city style="width:;height:" class="bgc">
  </select>
 </td>
    <td nowrap align="center" class="bgc">
  <input type="button" onClick="move(thisformlistthisformcity)" value="<<" class="buttons">
  <input type="button" onClick="move(thisformcitythisformlist)" value=">>" class="buttons">
 </td>
    <td>
  <select multiple size="" name="list" style="width:;height:" class="bgc">
  </select>
 </td>
  </tr>
    <tr class="bgc">
    <td colspan="" align="center"><input type="button" name="button" 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 = ; i < tboxoptionslength; i++) {
arrLookup[tboxoptions[i]text] = tboxoptions[i]value;
arrTbox[i] = tboxoptions[i]text;
}
var fLength = ;
var tLength = arrTboxlength;
for(i = ; i < fboxoptionslength; i++) {
arrLookup[fboxoptions[i]text] = fboxoptions[i]value;
if (fboxoptions[i]selected && fboxoptions[i]value != "") {
arrTbox[tLength] = fboxoptions[i]text;
tLength++;
}
else {
arrFbox[fLength] = fboxoptions[i]text;
fLength++;
   }
}
arrFboxsort();
arrTboxsort();
fboxlength = ;
tboxlength = ;
var c;
for(c = ; c < arrFboxlength; c++) {
var no = new Option();
novalue = arrLookup[arrFbox[c]];
notext = arrFbox[c];
fbox[c] = no;
}
for(c = ; c < arrTboxlength; c++) {
var no = new Option();
novalue = arrLookup[arrTbox[c]];
notext = arrTbox[c];
tbox[c] = no;
   }
}

  </script>
</body>


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20554.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.