jeffy

          BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
            70 Posts :: 1 Stories :: 14 Comments :: 0 Trackbacks

          實(shí)現(xiàn)兩個(gè)Web下拉選擇框關(guān)聯(lián)
            比如要實(shí)現(xiàn)國(guó)家Country與城市City的關(guān)聯(lián):
          動(dòng)態(tài)javascript方法實(shí)現(xiàn)如下:
             <!-- 引入js文件-->
             <script src="/scripts/xselect.js"></script>
            <script language="javascript">
            <!--    
           var dsy = new Dsy();
           //countryID是父select控件名稱, cityID是子select控件名稱.
           var sel = ["countryID","cityID"];
           //定義父與子兩個(gè)select控件的默認(rèn)值
           var def = ['<c:out value="${storeForm.countryID}" />','<c:out value="${storeForm.cityID}" />'];
           
           //父select控件內(nèi)容的定義
           dsy.add("0",[['-------','0']
           <logic:iterate name="CountryList" id="country">
               ,['<bean:write name="country" property="label"/>','<bean:write name="country" property="value"/>']
           </logic:iterate>
           ]);

           //下面定義子select控件的內(nèi)容
           dsy.add("0_0",[['------','0']]);
           <logic:iterate name="CountryList" id="country" indexId="index">
               dsy.add('0_<%=index.intValue()+1%>',[['------','0']
               <logic:iterate name="Citys" id="city">
                <bean:define id="c" name="city" property="countryID" />
               <bean:define id="c2" name="country" property="value" />
               //由于city.countryID是long類型,而country.value是String類型,所以把long類型轉(zhuǎn)換為String類型
                <%
                  String str = c + "";
               %>
                  //遍歷所有的City List, 如果city的countryID與country id一致,就加入select控件
                  <logic:equal name="country" property="value" value="<%=str%>">
            ,['<bean:write name="city" property="name"/>','<c:out value="${city.id}" />']
                  </logic:equal>
               </logic:iterate>]);
           </logic:iterate>
           
           attachSelect(dsy,sel,def);

            // -->
          </script>   
          //注意,上述代碼寫(xiě)到html form里面

          posted on 2006-02-05 16:18 Live-in Java 閱讀(540) 評(píng)論(0)  編輯  收藏 所屬分類: Others
          主站蜘蛛池模板: 黔江区| 库尔勒市| 东乡族自治县| 休宁县| 阿鲁科尔沁旗| 涟源市| 台湾省| 博白县| 油尖旺区| 江都市| 安阳县| 佛冈县| 英德市| SHOW| 久治县| 岐山县| 嘉禾县| 汝南县| 武夷山市| 敖汉旗| 景泰县| 呈贡县| 阳谷县| 江城| 凌云县| 游戏| 蒙自县| 青田县| 犍为县| 通江县| 怀安县| 醴陵市| 满洲里市| 长沙县| 志丹县| 浦东新区| 聊城市| 嘉祥县| 常宁市| 通城县| 稻城县|