实现的效果如下
当输入小写字母“z”的时候,刷出所有以z开头的国家

当输入汉字“美”的时候,刷出以美字开头的国家

1、使用java,SSH,Easyui
2、数据库设计,code:国家英语简写,note:中文注释,pycode:中文拼音缩写,english:英文名称
其中pycode全部为小写,note为中文名称,其余字段全部是大写

3、html代码
- <tr>
- <td class="left">
- <td clas="right"><input name="passport.country" id="country" ata-options="valueField: ‘CHN‘,textField: ‘中国‘" class="easyui-validatebox" required="true" style="width: 174px;"/>
- </td>
- </tr>
4、js代码
- $(function(){
-
- $(‘#country‘).combobox({
- valueField:‘english‘,
- textField:‘note‘,
- url:‘json/country.json‘,
- cache: false,
-
- onChange: function(newValue,oldValue){
-
- countrySearch(newValue);
- }
- });
- });
- function countrySearch(newValue){
-
-
- if((/[a-z]+/).test(newValue)||(/[\u4e00-\u9fa5]+/).test(newValue)){
- $(‘#country‘).combobox({
- valueField:‘english‘,
- textField:‘note‘,
- url:‘apply/countryCombobox_combobox.action?values=‘+encodeURI(encodeURI(newValue)),
- cache: false
-
- });
- }
-
- }
5、Action代码
- public String countryCombobox() throws Exception{
- log.info("=====下拉框查询国家代码========");
- values=URLDecoder.decode(values,"UTF-8");
- String fields;
-
- if(values.getBytes().length==values.length()){
- log.info("pycode");
- fields="pycode";
-
- }else{
- log.info("note");
- fields="note";
-
- }
-
- List list=comboboxService.findCountry(fields, values);
-
- this.jsonUtil(list);
- return null;
- }
6、接口
- public List findCountry(String fileds,String values) throws Exception;
7、接口实现类
- public List findCountry(String fields,String values) throws Exception{
- Criteria criteria=this.sessionFactory.getCurrentSession().createCriteria(CcountryTbl.class);
-
-
- if(StringUtils.isNotBlank(fields)&&StringUtils.isNotBlank(values)){
- criteria.add(Restrictions.like(fields, values+"%"));
- }
-
- return criteria.list();
- }
对261个国家地区快速查找选择
原文:http://www.cnblogs.com/henuyuxiang/p/4283010.html