searchableSelect 插件使用

news2024/9/28 7:24:40

在这里插入图片描述

<script type="text/javascript" src="//searchableSelect.js"></script>
<script>
	function getUserServer() {
	    var _this = '自定义封装接口请求、弹窗等方法';
	    _this.getAjax("get","//xxxxx/server", {}, function(res) {
	    	var data = res.data;
	        var serverList = "";
	        for(var i=0 ; i<data.length; i++){
	            serverList += '<option value="'+ data[i]['selectValue']+'">'
	            +	data[i]['selectName']
	            + '</option>';
	        }
	        var str = '<div>'
	        	+ '<div class="server">'
	        	+ 	'<label>select1:</label>'
	            + 	'<select id="userServer">'
	            + 		'<option value="">place select</option>'
	            + 		serverList
	            + 	'</select>'
	            + '</div>'
	            + '<div class="role">'
	            + 	'<label>select2:</label>'
	            + 	'<select id="userRole"><option value="">place select</option></select>'
	            + '</div>'
	            + '<a class="btn-alert " οnclick="paygift_new.bindRoleInfo()">确定</a>'
            	+ '</div>';
            _this.diyAlert({ title: "select选择框", showhtml: str });
	        
	        $('#userServer').searchableSelect();
	        $('#userRole').searchableSelect();
	        $("#userServer .searchable-select-item").click(function () {
	            _this.getUserRole($(this).attr('data-value'))
	        });
	    });
	}
	//获取角色信息
	function getUserRole(value) {
		var _this = '自定义封装接口请求、弹窗等方法';
	    _this.getAjax("get","//xxxxx/role",{id:value},function(res) {
	    	var data = res.data;
	        var roleList = '';
	        for(var i=0 ; i<data.length; i++) {
	            roleList += '<option value="'+ data[i]['roleValue']+'">' + data[i]['roleName'] + '</option>';
	        }
	        $("#userRole .searchable-select").remove();
	        $('#userRole').html(roleList).searchableSelect();
	    });
	}
</script>

searchableSelect 源码

// Author: David Qin
// E-mail: david@hereapp.cn
// Date: 2014-11-05

(function($){

    // a case insensitive jQuery :contains selector
    $.expr[":"].searchableSelectContains = $.expr.createPseudo(function(arg) {
      return function( elem ) {
        return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
      };
    });
  
    $.searchableSelect = function(element, options) {
      this.element = element;
      this.options = options || {};
      this.init();
  
      var _this = this;
  
      this.searchableElement.click(function(event){
        // event.stopPropagation();
        _this.show();
      }).on('keydown', function(event){
        if (event.which === 13 || event.which === 40 || event.which == 38){
          event.preventDefault();
          _this.show();
        }
      });
  
      $(document).on('click', null, function(event){
        if(_this.searchableElement.has($(event.target)).length === 0)
          _this.hide();
      });
  
      this.input.on('keydown', function(event){
        event.stopPropagation();
        if(event.which === 13){         //enter
          event.preventDefault();
          _this.selectCurrentHoverItem();
          _this.hide();
        } else if (event.which == 27) { //ese
          _this.hide();
        } else if (event.which == 40) { //down
          _this.hoverNextItem();
        } else if (event.which == 38) { //up
          _this.hoverPreviousItem();
        }
      }).on('keyup', function(event){
        if(event.which != 13 && event.which != 27 && event.which != 38 && event.which != 40)
          _this.filter();
      })
    }
  
    var $sS = $.searchableSelect;
  
    $sS.fn = $sS.prototype = {
      version: '0.0.1'
    };
  
    $sS.fn.extend = $sS.extend = $.extend;
  
    $sS.fn.extend({
      init: function(){
        var _this = this;
        this.element.hide();
  
        this.searchableElement = $('<div tabindex="0" class="searchable-select"></div>');
        this.holder = $('<div class="searchable-select-holder"></div>');
        this.dropdown = $('<div class="searchable-select-dropdown searchable-select-hide"></div>');
        this.input = $('<input type="text" class="searchable-select-input" />');
        this.items = $('<div class="searchable-select-items"></div>');
        this.caret = $('<span class="searchable-select-caret"></span>');
  
        this.scrollPart = $('<div class="searchable-scroll"></div>');
        this.hasPrivious = $('<div class="searchable-has-privious">...</div>');
        this.hasNext = $('<div class="searchable-has-next">...</div>');
  
        this.hasNext.on('mouseenter', function(){
          _this.hasNextTimer = null;
  
          var f = function(){
            var scrollTop = _this.items.scrollTop();
            _this.items.scrollTop(scrollTop + 20);
            _this.hasNextTimer = setTimeout(f, 50);
          }
  
          f();
        }).on('mouseleave', function(event) {
          clearTimeout(_this.hasNextTimer);
        });
  
        this.hasPrivious.on('mouseenter', function(){
          _this.hasPriviousTimer = null;
  
          var f = function(){
            var scrollTop = _this.items.scrollTop();
            _this.items.scrollTop(scrollTop - 20);
            _this.hasPriviousTimer = setTimeout(f, 50);
          }
  
          f();
        }).on('mouseleave', function(event) {
          clearTimeout(_this.hasPriviousTimer);
        });
  
        this.dropdown.append(this.input);
        this.dropdown.append(this.scrollPart);
  
        this.scrollPart.append(this.hasPrivious);
        this.scrollPart.append(this.items);
        this.scrollPart.append(this.hasNext);
  
        this.searchableElement.append(this.caret);
        this.searchableElement.append(this.holder);
        this.searchableElement.append(this.dropdown);
        this.element.after(this.searchableElement);
  
        this.buildItems();
        this.setPriviousAndNextVisibility();
      },
  
      filter: function(){
        var text = this.input.val();
        this.items.find('.searchable-select-item').addClass('searchable-select-hide');
        this.items.find('.searchable-select-item:searchableSelectContains('+text+')').removeClass('searchable-select-hide');
        if(this.currentSelectedItem.hasClass('searchable-select-hide') && this.items.find('.searchable-select-item:not(.searchable-select-hide)').length > 0){
          this.hoverFirstNotHideItem();
        }
  
        this.setPriviousAndNextVisibility();
      },
  
      hoverFirstNotHideItem: function(){
        this.hoverItem(this.items.find('.searchable-select-item:not(.searchable-select-hide)').first());
      },
  
      selectCurrentHoverItem: function(){
        if(!this.currentHoverItem.hasClass('searchable-select-hide'))
          this.selectItem(this.currentHoverItem);
      },
  
      hoverPreviousItem: function(){
        if(!this.hasCurrentHoverItem())
          this.hoverFirstNotHideItem();
        else{
          var prevItem = this.currentHoverItem.prevAll('.searchable-select-item:not(.searchable-select-hide):first')
          if(prevItem.length > 0)
            this.hoverItem(prevItem);
        }
      },
  
      hoverNextItem: function(){
        if(!this.hasCurrentHoverItem())
          this.hoverFirstNotHideItem();
        else{
          var nextItem = this.currentHoverItem.nextAll('.searchable-select-item:not(.searchable-select-hide):first')
          if(nextItem.length > 0)
            this.hoverItem(nextItem);
        }
      },
  
      buildItems: function(){
        var _this = this;
        this.element.find('option').each(function(){
          var item = $('<div class="searchable-select-item" data-value="'+$(this).attr('value')+'">'+$(this).text()+'</div>');
  
          if(this.selected){
            _this.selectItem(item);
            _this.hoverItem(item);
          }
  
          item.on('mouseenter', function(){
            $(this).addClass('hover');
          }).on('mouseleave', function(){
            $(this).removeClass('hover');
          }).click(function(event){
            event.stopPropagation();
            _this.selectItem($(this));
            _this.hide();
          });
  
          _this.items.append(item);
        });
  
        this.items.on('scroll', function(){
          _this.setPriviousAndNextVisibility();
        })
      },
      show: function(){
        this.dropdown.removeClass('searchable-select-hide');
        this.input.focus();
        this.status = 'show';
        this.setPriviousAndNextVisibility();
      },
  
      hide: function(){
        if(!(this.status === 'show'))
          return;
  
        if(this.items.find(':not(.searchable-select-hide)').length === 0)
            this.input.val('');
        this.dropdown.addClass('searchable-select-hide');
        this.searchableElement.trigger('focus');
        this.status = 'hide';
      },
  
      hasCurrentSelectedItem: function(){
        return this.currentSelectedItem && this.currentSelectedItem.length > 0;
      },
  
      selectItem: function(item){
        if(this.hasCurrentSelectedItem())
          this.currentSelectedItem.removeClass('selected');
  
        this.currentSelectedItem = item;
        item.addClass('selected');
  
        this.hoverItem(item);
  
        this.holder.text(item.text());
        var value = item.data('value');
        this.holder.data('value', value);
        this.element.val(value);
  
        if(this.options.afterSelectItem){
          this.options.afterSelectItem.apply(this);
        }
      },
  
      hasCurrentHoverItem: function(){
        return this.currentHoverItem && this.currentHoverItem.length > 0;
      },
  
      hoverItem: function(item){
        if(this.hasCurrentHoverItem())
          this.currentHoverItem.removeClass('hover');
  
        if(item.outerHeight() + item.position().top > this.items.height())
          this.items.scrollTop(this.items.scrollTop() + item.outerHeight() + item.position().top - this.items.height());
        else if(item.position().top < 0)
          this.items.scrollTop(this.items.scrollTop() + item.position().top);
  
        this.currentHoverItem = item;
        item.addClass('hover');
      },
  
      setPriviousAndNextVisibility: function(){
        if(this.items.scrollTop() === 0){
          this.hasPrivious.addClass('searchable-select-hide');
          this.scrollPart.removeClass('has-privious');
        } else {
          this.hasPrivious.removeClass('searchable-select-hide');
          this.scrollPart.addClass('has-privious');
        }
  
        if(this.items.scrollTop() + this.items.innerHeight() >= this.items[0].scrollHeight){
          this.hasNext.addClass('searchable-select-hide');
          this.scrollPart.removeClass('has-next');
        } else {
          this.hasNext.removeClass('searchable-select-hide');
          this.scrollPart.addClass('has-next');
        }
      }
    });
  
    $.fn.searchableSelect = function(options){
      this.each(function(){
        var sS = new $sS($(this), options);
      });
  
      return this;
    };
  
  })(jQuery);
  

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/186736.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

前端异常监控平台Sentry安装配置使用及问题

前言&#xff1a;Sentry是一款开源的异常监控平台,支持各种语言的SDK&#xff0c;通过对应SDK可以收集错误信息和性能数据&#xff0c;并可以再后台web页面中查看相关信息。官方地址&#xff1a;安装说明&#xff1a;https://develop.sentry.dev/self-hosted/后台使用说明&…

1.1计算机组成结构:CPU组成、冯·诺依曼结构与哈佛结构、嵌入式芯片术语

1.1计算机组成结构&#xff1a;CPU组成、冯诺依曼结构与哈佛结构、嵌入式芯片术语计算机组成结构CPU组成运算器控制器冯诺依曼结构与哈佛结构冯诺依曼结构哈佛结构嵌入式——芯片术语计算机组成结构 CPU组成 CPU分成两个部分&#xff0c;包括运算器和控制器。 CPU是计算机中核…

Linux之环境搭建

目录 一、VMware 二、centos7的安装 三、Mysql安装 四、 前端项目部署 1.确保前台项目能用 2.将前台项目打包npm run build 3.做ip/host主机映射 4.完成Nginx动静分离的default.conf的相关配置 5.将前端构件号的dist项目&#xff0c;上传到云服务器/usr/local/... …

[Swift]SDK开发

本文主要介绍使用swift语言制作framework Demo:https://github.com/Gamin-fzym/CMSDK 一、创建工程 1.创建目录 这里我创建了一个“CMSDK”目录 2.打开Xcode新建workspace放入CMSDK目录 这里命名为“CMSDK” 3.打开CMSDK.xcworkspace新建SDK工程放入CMSDK目录 这里还是命…

06 CSS-盒子模型【尚硅谷JavaWeb教程】

06 CSS-盒子模型【尚硅谷JavaWeb教程】 JAVAWEB的学习笔记 学习视频来自&#xff1a;https://www.bilibili.com/video/BV1AS4y177xJ/?vd_source75dce036dc8244310435eaf03de4e330 不同的浏览器导致前端展示页面不一样&#xff0c;盒子的大小的不同。&#xff08;所以前端要考虑…

奇迹mu开服教程

奇迹mu开服教程&#xff1a;开服服务端的架设及开服注意事项服务器推荐奇迹开服需要准备什么&#xff1f;开服大概成本分析奇迹MU商业服务端版本&#xff1a;1.02W、1.03H、1.03K、S6EP3、S7EP2、S9EP2&#xff1b;HE网站系统&#xff1a;绑定域名授权&#xff0c;功能可定制&a…

Jenkins部署项目一(物理机器部署SpringBoot项目)

一、Jenkins部署SpringBoot项目 设备&#xff1a;MacOS 准备工作 1.已安装java开发工具包JDK 2.已安装依赖管理工具Maven 3.已安装代码版本控制工具Git 4.已安装Jenkins learn-moon代码地址&#xff1a;https://github.com/BillDavidup/learn-moon SSH: gitgithub.com:Bil…

【学Vue就跟玩一样】如何使用集中式状态管理的Vuex以及如何模块化编码+命名空间

1.vuex是什么一个专门在Vue中实现集中式状态管理的一个Vue插件,可以对vue应用中多个组件的共享状态进行集中式的管理(读取/写入)&#xff0c;也是一种组件间通信的方式&#xff0c;并且适用于任意组件间通信2.什么时候使用Vuex1.多个组件依赖于同一状态2.来自不同组件的行为需要…

Goland入门指南(使用Goland创建并运行项目)

在文章《Goland下载和安装》详细介绍了 Goland 的安装和破解&#xff0c;本节我们来介绍一下怎么使用 Goland 来创建并运行一个项目。 创建项目 首先&#xff0c;在“文件”菜单中找到“New”&#xff0c;并在下一级菜单中选择“Project”来创建一个新项目。 为项目选择一个…

【vim】C语言代码提示

前言 常见的C语言提示插件是YouCompleteMe&#xff0c;这个插件安装比较麻烦&#xff0c;在这推荐一款coc.nvim这个插件&#xff0c;github仓库地址&#xff1a;https://github.com/neoclide/coc.nvim/ 下面是安装步骤。 一、安装 nodejs 1、终端命令安装 curl -sL instal…

SpringMVC DispatcherServlet源码(2) 扫描Controller创建HandlerMapping流程

Spring MVC向容器注册一个RequestMappingInfoHandlerMapping组件&#xff0c;他会扫描容器中的Controller组件&#xff0c;创建RequestMappingInfo并注册HandlerMethod映射关系。 本文将阅读Spring MVC源码分析上述流程。 RequestMappingHandlerMapping组件 Creates Request…

java ssm校园兼职发布与互动平台的设计与实现

该系统基于B/S即所谓浏览器/服务器模式&#xff0c;应用JSP技术&#xff0c;选择MySQL作为后台数据库。系统主要包括个人中心、用户管理、企业管理、企业信息管理、兼职信息管理、职位申请管理、职位类型管理、交流中心、留言反馈、系统管理等功能模块。 使用校园兼职发布与互动…

JavaWeb:会话技术之Session

Cookie已经能完成一次会话多次请求之间的数据共享&#xff0c;之前我们还提到过Session也可以实现&#xff0c;那么&#xff1a; 什么是Session&#xff1f;Session如何来使用&#xff1f;Session是如何实现的&#xff1f;Session的使用注意事项有哪些&#xff1f; 1. Sessio…

SpringCloud学习笔记 - 熔断降级 - Sentinel

1. Sentinel熔断降级概述 1.1. 熔断降级要解决的问题 除了流量控制以外&#xff0c;对调用链路中不稳定的资源进行熔断降级也是保障高可用的重要措施之一。一个服务常常会调用别的模块&#xff0c;可能是另外的一个远程服务、数据库&#xff0c;或者第三方 API 等。例如&…

海康Visionmaster-VM权限设置、软件设置、方案设置和运行策略

权限设置 权限设置可设置是否配置管理员、技术员和操作员权限和配置密码&#xff0c;并设置不同角色人员的权限。 权限导入导出可对当前软件权限设置模块的配置以txt格式文档进行导入或导出。 打开启用加密时&#xff0c;需设置管理员密码。设置完成后&#xff0c;软件以管理员…

如何把Node项目部署到服务器上

1. 如何合理选购一台服务器 对于服务器的选择&#xff0c;我们主要有以下几种选择&#xff1a; 1. 阿里云&#xff1b; 2. 腾讯云&#xff1b; 3. 华为云&#xff1b; 4. 亚马逊云&#xff1b; 国内用户如果没有特殊需求可以选择前三种&#xff0c;这里我阿里云举例&…

【Vue】vue-devtools调试工具安装和配置

1. 安装 vue-devtools 调试工具vue 官方提供的 vue-devtools 调试工具&#xff0c;能够方便开发者对 vue 项目进行调试与开发。Chrome 浏览器在线安装 vue-devtools &#xff1a;https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpdFi…

RPA自动办公02——Uibot界面元素选择

继续RPA-Uibot的简单使用&#xff0c;本次带来RPA自动点击网页。 当然官方教程更加详细&#xff1a;界面元素自动化_UiBot开发者指南 按照书上的教程&#xff0c;点击一个表格&#xff0c;在右边拖拽命令&#xff0c;然后选择元素就可以了&#xff1a; 这个表格在官方文档上有…

为什么要开发SpringBoot?

Spring配置繁琐 虽然Spring的组件代码是轻量级的&#xff0c;但它的配置却是重量级的。一开始&#xff0c;Spring用XML配置&#xff0c;而且是很多 XML配置。Spring 2.5引入了基于注解的组件扫描&#xff0c;这消除了大量针对应用程序自身组件的显式XML配置。Spring 3.0引入了基…

计算机图形学 第4章 多边形填充

目录前驱知识多边形的扫描转换有效边表填充算法原理边界像素处理原则怎么算交点有效边桶表与边表桶表表示法边缘填充算法填充过程在这里插入图片描述区域填充算法/种子填充算法种子填充算法扫描线种子填充算法 &#xff08;更有效&#xff09;前驱知识 了解扫描转换的基本概念…