jeffy

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            70 Posts :: 1 Stories :: 14 Comments :: 0 Trackbacks

          實現兩個Web下拉選擇框關聯
            比如要實現國家Country與城市City的關聯:
          動態javascript方法實現如下:
             <!-- 引入js文件-->
             <script src="/scripts/xselect.js"></script>
            <script language="javascript">
            <!--    
           var dsy = new Dsy();
           //countryID是父select控件名稱, cityID是子select控件名稱.
           var sel = ["countryID","cityID"];
           //定義父與子兩個select控件的默認值
           var def = ['<c:out value="${storeForm.countryID}" />','<c:out value="${storeForm.cityID}" />'];
           
           //父select控件內容的定義
           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控件的內容
           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類型轉換為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>   
          //注意,上述代碼寫到html form里面

          posted on 2006-02-05 16:18 Live-in Java 閱讀(541) 評論(0)  編輯  收藏 所屬分類: Others
          主站蜘蛛池模板: 惠州市| 凯里市| 周至县| 万荣县| 历史| 衡阳市| 土默特左旗| 昌宁县| 海伦市| 尤溪县| 兴山县| 铜梁县| 禄丰县| 荔波县| 克拉玛依市| 阿拉善盟| 苏州市| 平陆县| 新营市| 苗栗县| 云梦县| 延吉市| 阿勒泰市| 莎车县| 寿宁县| 深泽县| 张家界市| 来安县| 垫江县| 承德县| 巨野县| 布拖县| 隆尧县| 厦门市| 韩城市| 奇台县| 哈巴河县| 肥乡县| 门头沟区| 江源县| 延吉市|