Home > Web Front-end > JS Tutorial > body text

jQuery中select插件实现异步实时搜索的方法

黄舟
Release: 2017-10-26 10:30:27
Original
1976 people have browsed it

这篇文章主要介绍了jquery select插件异步实时搜索实例代码,需要的朋友可以参考下

一、先看看效果。

二、做此插件的原因。

  1.数据量过大(几千、几万条),无法一次性全部加载。

  2.现有插件各不相同,无法满足功能需求。

  3.美观性,可控性不足。

三、如何使用。

  1.html和js


 
 
 
Copy after login

  2.实例。


# 使用实例
    var initUrl = "/demo/defineDict.do?method=getEnterpriseDict&unitName="+encodeURIComponent(encodeURIComponent("xx无烟煤矿业集团有限责任公司"));
    var ajaxUrl = "/demo/defineDict.do?method=getEnterpriseDict&unitName=";
    var $select = $("#ajaxselect").ajaxselect({
      initUrl:initUrl,
      ajaxUrl:ajaxUrl,
      defkv:['id','text'],
      selected:0,
    },function(filterData,isInit){
      //filter
      console.log(filterData);
    },function(cbData,isInit){
      //callback
      console.log(cbData);
    });
    $select.on("change", function(){
      console.log(this.value);
    });
Copy after login

3.详细配置。


var defcfg = {
  initUrl:'',      //初始化请求地址
  ajaxUrl:'',      //异步请求地址
  defkv:[],      //返回数据 的key
  delay:200,      //ajax回调 延时
  width:200,      //input 宽度
  height:30,      //input 高度
  selected:-1,    //初始化数据 默认选中项,-1为不选中
  limit:20,      //最大显示条数,0为不限制
  maxheight:250,    //最大显示高度
  hoverbg:'#189FD9',  //悬浮背景色
  activebg:'#5FB878',  //选中项背景色
  style:''      //自定义样式
};
Copy after login

   还有一些其它的api,详细请看参考链接、源码。

四:声明:

本插件是根据现有插件,根据自己的需求修改而来。如有小问题请自行修改源码即可。

如果不是异步搜索,其它插件譬如layui、select2也是不错的选择。

另外此插件依赖jquery。

总结

The above is the detailed content of jQuery中select插件实现异步实时搜索的方法. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!