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:ㄚ孝]
alanting

Alan Ting



發文: 200
積分: 3
於 2003-06-22 23:21 user profilesend a private message to usersend email to alantingreply 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 的關連下拉選單,因為你要三層跟二層設計其實是一樣的
//抓取你要對映的主要Key值EX:國別
int i;//這是要給javascript 中的陣列值
stmt = Conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
stmt2 = Conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
SQL = "Select * From country";
rs = stmt.executeQuery(SQL);
%>

<script>
function ChangeSelect(country, city)<===分別將國家及城市代入javascript的function中,此部分會在html中詳解
{
val = country.options[country.options.selectedIndex].value; <==抓取表單country中的index值
  
  <%while(rs.next()){
  SQL2 = "select * from 城市";
  
  rs2 = stmt2.executeQuery(SQL2);
  %>
  if (val == '<%=rs.getString("國別名稱")%>')
  {
    
    <%while(rs2.next()){//計算出有多少的city在這個國家中
      i++;
    }%>
    city.length = <%=i%>; <==表單中city的下拉表單長度
    <%
    i=0;
    rs2.first();//回到城市第一筆資料
    do{%>
    city.options[<%=i%>].value = '<%=rs2.getInt("城市代碼")//這是下拉表單中value的值,你也可以代入其他資料%>'; city.options[<%=i%>].text = '<%=rs2.getString("城市名稱")//這是下拉表單中文字顯示部分%>';
    <%
    i++;
    }while(rs2.next());
    i=0;%>
  }
  <%}
  rs.first();//要回到第一筆的原因是因為你要把國別抓入html的select中%>
}
</script>

====Html表現方式====
<form name="selection">
<select name=country onChange="ChangeSelect(document.selection.country,document.selection.city)" size="1">
                   <option>==請選擇國家==</option>
                   <%do{%>
                   <option value="<%=rs.getString("國別名稱")%>"><%=rs.getString("國別名稱")%></option>
                   <%}while(rs.next());%>
                   </select><BR>
                 選擇您要的城市</font><br>
                   <SELECT name=city>

                   </SELECT> </p>


reply to postreply to post
重新學習...拜讀各位大大的巨作中..
話題樹型展開
人氣 標題 作者 字數 發文時間
81190 [精華] [問題]即時多層下拉選單 ㄚ孝 384 2003-06-07 09:05
78361 Re:[問題]即時多層下拉選單 browser 1054 2003-06-07 18:19
75292 Re:[問題]即時多層下拉選單 x3711699 138 2004-04-08 20:41
75104 Re:[問題]即時多層下拉選單 alanting 710 2004-04-11 01:41
78339 Re:[問題]即時多層下拉選單 AdaHsu 3345 2004-04-19 12:23
76213 Re:[問題]即時多層下拉選單 tsechun 95 2004-04-21 02:01
73370 Re:[問題]即時多層下拉選單 andowson 474 2004-08-01 11:07
73096 Re:[問題]即時多層下拉選單 yingssu 663 2004-08-01 19:48
72172 Re:[問題]即時多層下拉選單 ting626 38 2004-08-25 16:57
72237 Re:[問題]即時多層下拉選單 i22616899 2298 2004-09-04 17:55
71426 Re:[問題]即時多層下拉選單 GuanChih 175 2004-09-05 18:51
72162 Re:[問題]即時多層下拉選單 jonz 873 2004-09-12 10:27
65413 Re:[問題]即時多層下拉選單 pulse 1193 2005-04-18 23:22
69219 Re:[問題]即時多層下拉選單 joshua 1019 2004-11-17 16:02
69542 Re:[問題]即時多層下拉選單 joshua 2357 2004-11-17 17:27
75806 Re:[問題]即時多層下拉選單 ㄚ孝 61 2003-06-09 08:34
76029 Re:[問題]即時多層下拉選單 browser 135 2003-06-09 09:23
68252 Re:[問題]即時多層下拉選單 Madagascar 141 2004-12-04 02:06
68063 Re:[問題]即時多層下拉選單 yannru 360 2004-12-07 16:19
67927 Re:[問題]即時多層下拉選單 Madagascar 465 2004-12-07 21:20
67921 Re:[問題]即時多層下拉選單 small3 388 2004-12-13 09:52
68304 Re:[問題]即時多層下拉選單 EPHT 3599 2004-12-18 09:45
55684 Re:[問題]即時多層下拉選單 yulie 2015 2006-06-06 12:47
55403 Re:[問題]即時多層下拉選單 yulie 102 2006-06-06 13:21
55676 Re:[問題]即時多層下拉選單 estrelas 1620 2006-06-06 18:51
46469 Re:[問題]即時多層下拉選單 minichitina 1875 2007-05-05 16:25
46363 Re:[問題]即時多層下拉選單 eidson72 4781 2007-05-16 11:48
21258 Re:[問題]即時多層下拉選單 catte 1960 2011-06-27 14:44
21149 Re:[問題]即時多層下拉選單 bernardvai 54 2011-06-27 16:56
45942 Re:[問題]即時多層下拉選單 alvin0224 309 2007-05-16 14:54
46020 Re:[問題]即時多層下拉選單 eidson72 21 2007-05-16 15:41
75621 Re:[問題]即時多層下拉選單 ㄚ孝 75 2003-06-09 14:05
75582 Re:[問題]即時多層下拉選單 jackyliu 201 2003-06-22 02:06
45471 Re:[問題]即時多層下拉選單 minichitina 188 2007-05-31 08:33
45334 Re:[問題]即時多層下拉選單 minichitina 2335 2007-06-04 08:04
45803 Re:[問題]即時多層下拉選單 minichitina 2718 2007-06-07 08:00
21260 Re:[問題]即時多層下拉選單 catte 2014 2011-06-28 03:14
21112 Re:[問題]即時多層下拉選單 bernardvai 1202 2011-06-28 09:54
21224 Re:[問題]即時多層下拉選單 catte 2970 2011-06-28 11:36
21087 Re:[問題]即時多層下拉選單 bernardvai 545 2011-06-28 14:21
21176 Re:[問題]即時多層下拉選單 catte 146 2011-06-28 17:54
21101 Re:[問題]即時多層下拉選單 bernardvai 2904 2011-06-29 09:58
21054 Re:[問題]即時多層下拉選單 catte 43 2011-06-29 21:58
20939 Re:[問題]即時多層下拉選單 bernardvai 219 2011-06-30 14:40
20752 Re:[問題]即時多層下拉選單 catte 269 2011-07-13 10:41
20830 Re:[問題]即時多層下拉選單 bernardvai 660 2011-07-13 11:34
20249 Re:[問題]即時多層下拉選單 catte 4035 2011-08-15 09:35
20477 Re:[問題]即時多層下拉選單 jk47 288 2011-08-15 11:19
75555 Re:[問題]即時多層下拉選單 mousetail 89 2003-06-22 13:06
77190 Re:[問題]即時多層下拉選單 alanting 1777 2003-06-22 23:21
75718 Re:[問題]即時多層下拉選單 alanting 87 2003-06-22 23:24
21376 Re:[問題]即時多層下拉選單 catte 54 2011-06-27 04:33
75134 Re:[問題]即時多層下拉選單 evenlin 132 2003-08-02 00:55
77280 Re:[問題]即時多層下拉選單 anthonycs 301 2003-08-02 15:43
74770 Re:[問題]即時多層下拉選單 ajax0953 232 2004-03-31 15:05
74516 Re:[問題]即時多層下拉選單 shyan68 261 2004-04-07 18:11
72960 Re:[問題]即時多層下拉選單 yafeng 122 2004-07-29 10:53
68400 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