JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Servlet/JSP 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
EPHT





發文: 1
積分: 0
於 2004-12-18 09:45 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
之前作專案時也有遇到類似的需求...

因為當時選單的資料量不大,所以是在後端一次將資料取得之後,再配合 JavaScript....

為了讓畫面可以簡潔一點,寫了一組 tag 將 Java 中的 Collection, Map, String[], String[][], String[][][] 轉換為 JavaScript 的 Array 使用...

tag 的 Source Code 在附檔的 ScriptArray.jar 中......
其中,使用到的 RequestUtils 是從 Struts 借用來的
範列 demo.jsp 中除了使用 自訂的 tag 外,也使用了 jakarta 的 input tag,提供給有興趣的參考參考囉:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=BIG5" pageEncoding="BIG5"%>
<%@ page import="java.util.HashMap" %>
 
<%@ taglib uri="/demo" prefix="demo" %>
<%@ taglib uri="/input" prefix="input" %>
 
<%
/* =========== (A) 此段模擬後端取得之資料 =========== */
HashMap countryMap = new HashMap();
countryMap.put("--", "--");
countryMap.put("台灣", "Taiwan");
countryMap.put("日本", "Japan");
 
String[][][] cities = new String[3][][];
 
cities[0] = new String[][]{{"--", ""}, {"--","--"}};
cities[1] = new String[][]{{"Taiwan",""}, {"台北", "Taipei" }, {"台南", "Tainan" }};
cities[2] = new String[][]{{"Japan",""}, {"東京", "Tokyo" }, {"京都", "Kyoto" }};
 
String[][][] others = new String[5][][];
 
others[0] = new String[][]{{"--", ""}, {"--","--"}};
others[1] = new String[][]{{"Taipei",""}, {"台北_1", "Taipei1" }, {"台北_2", "Taipei2" }};
others[2] = new String[][]{{"Tainan",""}, {"台南_1", "Tainan1" }, {"台南_2", "Tainan2" }};
others[3] = new String[][]{{"Tokyo",""}, {"東京_1", "Tokyo1" }, {"東京_2", "Tokyo2" }};
others[4] = new String[][]{{"Kyoto",""}, {"京都_1", "Kyoto1" }, {"京都_2", "Kyoto2" }};
/* =========== (A) End ============================= */
 
pageContext.setAttribute("cities", cities);
pageContext.setAttribute("others", others);
%>
 
<meta http-equiv="Content-Type" content="text/html; charset=big5">
 
<TITLE>DEMO</TITLE>
 
<demo:ScriptArray varName="varCityOptions" scope="page" name="cities"/>
<demo:ScriptArray varName="varOtherOptions" scope="page" name="others"/>
 
<Script>
function changeOption( master, detail, detailOption ){
  var varValue = master.value;
  var varMasterNum = detailOption.length;
 
  for(var i=0; i<varMasterNum ; i++){  
    if( varValue == detailOption[i][0][0] ){
      initOption( detail );
      
      var varDetailNum = detailOption[i].length;
      detail.length = varDetailNum;      
      for( var j=1; j<varDetailNum ; j++){
        detail.options[ j ] = new Option( detailOption[ i ][ j ][ 0 ],detailOption[ i ][ j ][ 1 ] );    
      }
      break;
    }
  }
}
 
function initOption( target ){
  if( target.length ){
    target.length = 1;
    target.options[ 0 ] = new Option("--", "--" );              
  }
}
</Script>
</head>
 
<body>
 
<input:select name="country" options="<%=countryMap%>" 
attributesText=" onchange='changeOption( this, city ,  varCityOptions); initOption( other )' " />
 
<select name="city" onchange='changeOption( this, other ,  varOtherOptions)'>
  <option value="--">--</option>
</select>
 
<select name="other" >
  <option value="--">--</option>
</select>
 
</body>
</html>
 


- End -

ScriptArray.jar (4.79k)


EPHT edited on 2004-12-23 14:44
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
81019 [精華] [問題]即時多層下拉選單 ㄚ孝 384 2003-06-07 09:05
78205 Re:[問題]即時多層下拉選單 browser 1054 2003-06-07 18:19
75142 Re:[問題]即時多層下拉選單 x3711699 138 2004-04-08 20:41
74955 Re:[問題]即時多層下拉選單 alanting 710 2004-04-11 01:41
78183 Re:[問題]即時多層下拉選單 AdaHsu 3345 2004-04-19 12:23
76058 Re:[問題]即時多層下拉選單 tsechun 95 2004-04-21 02:01
73218 Re:[問題]即時多層下拉選單 andowson 474 2004-08-01 11:07
72948 Re:[問題]即時多層下拉選單 yingssu 663 2004-08-01 19:48
72020 Re:[問題]即時多層下拉選單 ting626 38 2004-08-25 16:57
72085 Re:[問題]即時多層下拉選單 i22616899 2298 2004-09-04 17:55
71276 Re:[問題]即時多層下拉選單 GuanChih 175 2004-09-05 18:51
72010 Re:[問題]即時多層下拉選單 jonz 873 2004-09-12 10:27
65261 Re:[問題]即時多層下拉選單 pulse 1193 2005-04-18 23:22
69068 Re:[問題]即時多層下拉選單 joshua 1019 2004-11-17 16:02
69389 Re:[問題]即時多層下拉選單 joshua 2357 2004-11-17 17:27
75651 Re:[問題]即時多層下拉選單 ㄚ孝 61 2003-06-09 08:34
75875 Re:[問題]即時多層下拉選單 browser 135 2003-06-09 09:23
68099 Re:[問題]即時多層下拉選單 Madagascar 141 2004-12-04 02:06
67913 Re:[問題]即時多層下拉選單 yannru 360 2004-12-07 16:19
67777 Re:[問題]即時多層下拉選單 Madagascar 465 2004-12-07 21:20
67769 Re:[問題]即時多層下拉選單 small3 388 2004-12-13 09:52
68154 Re:[問題]即時多層下拉選單 EPHT 3599 2004-12-18 09:45
55533 Re:[問題]即時多層下拉選單 yulie 2015 2006-06-06 12:47
55251 Re:[問題]即時多層下拉選單 yulie 102 2006-06-06 13:21
55526 Re:[問題]即時多層下拉選單 estrelas 1620 2006-06-06 18:51
46318 Re:[問題]即時多層下拉選單 minichitina 1875 2007-05-05 16:25
46210 Re:[問題]即時多層下拉選單 eidson72 4781 2007-05-16 11:48
21106 Re:[問題]即時多層下拉選單 catte 1960 2011-06-27 14:44
20999 Re:[問題]即時多層下拉選單 bernardvai 54 2011-06-27 16:56
45791 Re:[問題]即時多層下拉選單 alvin0224 309 2007-05-16 14:54
45868 Re:[問題]即時多層下拉選單 eidson72 21 2007-05-16 15:41
75465 Re:[問題]即時多層下拉選單 ㄚ孝 75 2003-06-09 14:05
75429 Re:[問題]即時多層下拉選單 jackyliu 201 2003-06-22 02:06
45321 Re:[問題]即時多層下拉選單 minichitina 188 2007-05-31 08:33
45181 Re:[問題]即時多層下拉選單 minichitina 2335 2007-06-04 08:04
45650 Re:[問題]即時多層下拉選單 minichitina 2718 2007-06-07 08:00
21106 Re:[問題]即時多層下拉選單 catte 2014 2011-06-28 03:14
20962 Re:[問題]即時多層下拉選單 bernardvai 1202 2011-06-28 09:54
21072 Re:[問題]即時多層下拉選單 catte 2970 2011-06-28 11:36
20937 Re:[問題]即時多層下拉選單 bernardvai 545 2011-06-28 14:21
21024 Re:[問題]即時多層下拉選單 catte 146 2011-06-28 17:54
20951 Re:[問題]即時多層下拉選單 bernardvai 2904 2011-06-29 09:58
20902 Re:[問題]即時多層下拉選單 catte 43 2011-06-29 21:58
20789 Re:[問題]即時多層下拉選單 bernardvai 219 2011-06-30 14:40
20600 Re:[問題]即時多層下拉選單 catte 269 2011-07-13 10:41
20682 Re:[問題]即時多層下拉選單 bernardvai 660 2011-07-13 11:34
20097 Re:[問題]即時多層下拉選單 catte 4035 2011-08-15 09:35
20321 Re:[問題]即時多層下拉選單 jk47 288 2011-08-15 11:19
75402 Re:[問題]即時多層下拉選單 mousetail 89 2003-06-22 13:06
77035 Re:[問題]即時多層下拉選單 alanting 1777 2003-06-22 23:21
75565 Re:[問題]即時多層下拉選單 alanting 87 2003-06-22 23:24
21224 Re:[問題]即時多層下拉選單 catte 54 2011-06-27 04:33
74980 Re:[問題]即時多層下拉選單 evenlin 132 2003-08-02 00:55
77126 Re:[問題]即時多層下拉選單 anthonycs 301 2003-08-02 15:43
74619 Re:[問題]即時多層下拉選單 ajax0953 232 2004-03-31 15:05
74366 Re:[問題]即時多層下拉選單 shyan68 261 2004-04-07 18:11
72809 Re:[問題]即時多層下拉選單 yafeng 122 2004-07-29 10:53
68249 Re:[問題]即時多層下拉選單 javaer 216 2004-12-20 00:40
» JWorld@TW »  Servlet/JSP 討論區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8