日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jQueryui autocomplete使用示例

發布時間:2025/7/14 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jQueryui autocomplete使用示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

html標簽:

<input id="province" name="province"></li> <input id="city" name="city" type="text"></li>

?

需要引入的js文件:

<script src="js/jquery.min.js"></script><script src="js/jquery-ui.min.js"></script>

頁面上的javascript代碼

<script>var url = "<%=servlet.getPath() %>";var lastXhr;$("#province").autocomplete({minLength: 1,source: function (request, response) {var term = request.term;lastXhr = $.getJSON(url+"?beanName=ProvinceData", request, function (data, status, xhr) {if (xhr === lastXhr) {response( $.grep( data, function( item ){if(item.indexOf(request.term)!=-1)return item;}) ); }});},select:function(event, ui){$("#city").autocomplete({minLength:1,source:function(request1,response1){var term = request1.term;$.getJSON(url+"?beanName=CityData&province="+ui.item.value,request1,function(data1,status1,xhr1){response1($.grep(data1,function(item){if(item.indexOf(request1.term)!=-1)return item;}));});}});}}); </script>

服務端的java代碼:

@BeanDef(value="ProvinceData",scope=PrototypeScope.class)public static Object provinceData(@BeanRef ProvinceService provinceService) throws Exception{List<Province> provinces = provinceService.getProvinceByName(new String(""));List<String> nameList = new ArrayList<String>();for(Province province:provinces){nameList.add(province.getName());}JsonModel model = new JsonModel(nameList);return model;}@BeanDef(value="CityData",scope=PrototypeScope.class)public static Object cityData(@Param("province")String province,@BeanRef ProvinceService provinceService,@BeanRef CityService cityService) throws Exception{System.out.println(province);List<Province> provinces = provinceService.getProvinceByName(province);List<String> nameList = new ArrayList<String>();if(provinces != null && provinces.size()==1){List<City> cities = cityService.getCityByProvinceID(provinces.get(0).getId());for(City city:cities){nameList.add(city.getName());}}else{nameList.add("");}JsonModel model = new JsonModel(nameList);System.out.println(model.toString());return model;}

?

轉載于:https://www.cnblogs.com/blackckat-hm/p/3873815.html

總結

以上是生活随笔為你收集整理的jQueryui autocomplete使用示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。