posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          ajax 的 輸入選擇 (同google&讀數據庫)

          Posted on 2007-07-25 17:05 G_G 閱讀(1275) 評論(2)  編輯  收藏 所屬分類: javascript
          問題: 用戶在 WEB 中輸入 機車 人員 等項 頁面會根據當前字符給出選擇提示
          解決:scriptaculous javascript工具包的 Autocompleter.Local


          與圖對應代碼:
          <TD><html:checkbox?property="value(Yloco)"?value="Y"/>機車</TD>
          <TD><input?id="loco"?type="text"?name="value(loco)"?size="20"?value="${map['loco']}"?onkeyup="getData();"></TD>
          <div?id="locoupdate"?style="display:none;border:1px?solid?black;background-color:white;height:150px;overflow:auto;"></div>????

          javascript 處理方法
          ?? var arr = new Array();
          ?? //關鍵方法
          scriptaculous框架 提供方法
          ?? //要使用 此方法 先到入 prototype.js? effects.js?? controls.js
          ?? new Autocompleter.Local('loco','locoupdate',
          ? ?? ??? ??? ??? ??? ?arr, { tokens: new Array(',','\n'), fullSearch: true, partialSearch: true});
          ??
          function?getData(){???
          ??? ?? ?? ? //得到 字符數組 str,str,str.....
          ????????????
          var?url?=?"/jczb/jczb/meanwhileDiary.do?method=loco&par="+document.getElementById("loco").value;????
          ????????????
          new?Ajax.Request(
          ????????????????????url,
          ????????????????????{
          ????????????????????????method:?'get',
          ????????????????????????onComplete:?action??????????????
          ????????????????});????
          ????}
          ????
          function?action(req){
          ????????????
          var?str?=?req.responseText.split(",")?;
          ????????????
          while(!arr.length==0){
          ????????????????arr.pop();
          ????????????}

          ????????????
          for(?var?jj=0;jj<str.length-1;jj++?){
          ????????????????????arr[jj]?
          =?str[jj];
          ????????????}
          ????????}



          完整jsp


          ?
          心得:多看書 是有幫助的

          評論

          # re: ajax 的 輸入選擇 (同google&讀數據庫)   回復  更多評論   

          2007-07-26 19:33 by dfjinn
          這種方法是每輸一個字就查詢一次數據庫,如果對一個打字速度快的用戶,那勢必會對數據造成較大的壓力。

          # re: ajax 的 輸入選擇 (同google&讀數據庫) [未登錄]  回復  更多評論   

          2007-07-30 09:50 by G_G
          我寫到這份上了 應該可以安你的想法改 是很 好改的了
          主站蜘蛛池模板: 中山市| 金溪县| 喀喇沁旗| 安溪县| 墨竹工卡县| 界首市| 县级市| 裕民县| 雅江县| 东乡族自治县| 印江| 雷州市| 江陵县| 嘉祥县| 台州市| 沭阳县| 武邑县| 荣昌县| 德惠市| 普兰县| 辉县市| 固原市| 渝中区| 收藏| 白玉县| 滦南县| 青州市| 仁布县| 北川| 天气| 德惠市| 古蔺县| 五家渠市| 阜康市| 吉木乃县| 甘泉县| 昭平县| 新竹县| 陇川县| 汕尾市| 余干县|