由于后端开发需要一个下拉控件,能输入,能选择,于是自己写了一个

;(function($,window,document,undefined){
function Select(el,opt){
this.$el = el;
this.default={
title:'选择类别',
showTitle:true,
wth:'',// ''100%,half:50%,third:30%
require:true,
items:[{
id:"01",
contxt:'项目一'
},{
id:"02",
contxt:'项目二'
}]
}
this.settings = $.extend({},this.default,opt);
}
Select.prototype={
init:function(){
var that = this,
$html=$('<div class="title"><span class="eis-require">*</span>\n'+
that.settings.title+
'</div>\n'+
'<div class="es-input-wrapper">\n' +
' <div class="input-box">\n' +
' <input type="text" value="" placeholder="'+that.settings.title+'">\n'+
'<i class="fa fa-angle-down"></i>\n' +
'<ul class="eis-new-form-dropmenu"></ul>'+
' </div>\n' +
' </div>');
that.$el.append($html);
var $list=that.$el.find('.eis-new-form-dropmenu'),
$require = that.$el.find('.eis-require'),
$input = that.$el.find('input[type="text"]'),
$title=that.$el.find('.title'),
$inputWrapper=that.$el.find('.es-input-wrapper');
//判断显示标题
if(that.settings.showTitle===false){
$title.remove()
$inputWrapper.css({'margin-left':"0"})
}else{
$inputWrapper.css({'margin-left':"100"})
}
if(!that.$el.hasClass('es-form-group')){
that.$el.addClass('es-form-group')
}
switch (that.settings.wth){
case '':
break
case 'half':
that.$el.addClass('half');
break;
case 'third':
that.$el.addClass('third')
}
// 添加下拉列表
var $listHtml = '';
if(that.settings.items && that.settings.items.length>0){
for(var i = 0;i<that.settings.items.length;i++){
$listHtml+='<li class="eis-dropmenu-item">'+that.settings.items[i]['contxt']+'</li>'
}
$list.html($listHtml)
}
//判断显示必填
if(that.settings.require){
$require.text('*')
}else(
$require.text('')
)
//下拉展示收缩
var $dropToggle = that.$el.find('.fa');
$dropToggle.on('click',function(e){
if(e){
e.stopPropagation();
}else{
window.event.cancelBubble=true
}
if($(this).get(0).style['transform']==''){
$(this).get(0).style['transform']='translate(0,-50%) rotate(180deg)';
}else if( $(this).get(0).style['transform']==='translate(0px, -50%) rotate(180deg)'){
$(this).get(0).style['transform']='translate(0,-50%) rotate(0deg)';
}else{
$(this).get(0).style['transform']='translate(0,-50%) rotate(180deg)'
}
$list.slideToggle()
})
var $listItem = $list.find('.eis-dropmenu-item');
$listItem.each(function(){
$(this).on('click',function(e){
if(e){
e.stopPropagation();
}else{
window.event.cancelBubble=true
}
$input.val('');
$input.val($(this).text())
$list.slideToggle()
})
})
$(document).on('click',function(){
$list.hide();
})
}
}
$.fn.extend({
select:function(opt){
return this.each(function(){
new Select($(this),opt).init()
})
}
})
})(jQuery,window,document)

外部调用

$(function(){
$('#select').select({
title:'联系人',//标题
wth:'half',// ''100%,half:50%,third:30%
require:true,//true,显示红*,false不显示
showTitle:false,//是否显示标题
//item数据
items:[{
id:"01",
contxt:'项目一'
},{
id:"02",
contxt:'项目二'
}]
})
})

下拉控件jQuery插件的更多相关文章

  1. java 下拉控件 转自 http://www.cnblogs.com/lhb25/p/form-enhanced-with-javascript-three.html

    表单元素让人爱恨交加.作为网页最重要的组成部分,表单几乎无处不在,从简单的邮件订阅.登陆注册到复杂的需要多页填写的信息提交功能,表单都让开发者花费了大量的时间和精力去处理,以期实现好用又漂亮的表单功能 ...

  2. 一不小心写了个bootstrap风格下拉控件 JqueryUI + bootstrap

    受够了EasyUI的封闭,Bootstrap虽然华丽但是功能太渣,闲着无聊写个下拉控件玩玩吧,不喜勿喷哈... 第一步:先设计下我的下拉控件的样子 1.既然是bootstrap风格的,我想应该是这样的 ...

  3. DevExpress控件GridView挂下拉控件无法对上值

    下拉控件使用RepositoryItemLookUpEdit,加入如下事件进行处理. repositoryItemLookUpEdit1.CustomDisplayText += new DevExp ...

  4. scrollview嵌套下拉控件嵌套recyclerview(不动第三方原基础自定义)

    相信会碰到很多类似的需求,一个列表控件,然后控件上方的一个头部需要自定义,这样就不好有时候也不能加在列表控件的头部了,那必须得嵌套一层scrollview了,没毛病,那么一般的列表控件都是有上拉下拉的 ...

  5. 基于bootstrap的multiple-select下拉控件使用

    multiple-select是一款优秀的下拉菜单控件,能够支持单选和多选. 详细参考文档: JS组件系列——两种bootstrap multiselect组件大比拼 multiple-select ...

  6. 解决easyUI下拉控件无法触发onkeydown事件

    实现在combotree下拉控件中按Backspace键清除combotree选中的值 下面的代码无法获取到键盘事件 <input class="easyui-combotree&qu ...

  7. 使用谷歌提供的SwipeRefreshLayout下拉控件,并自定义实现下拉加载的功能

    package com.loaderman.swiperefreshdemo; import android.os.Bundle; import android.os.Handler; import ...

  8. SDI在自定义的工具栏上添加下拉控件

    0.首先到自己的工具条上新建一个控件,并命名新ID 1.拷贝FlatComboBox.h和FlatComboBox.cpp到工程目录下 2.建立新类 class CTrackerToolBar : p ...

  9. JQuery下拉控件select的操作汇总

    JQuery获取和设置Select选项方法汇总如下: 获取select 先看看下面代码:   $("#select_id").change(function(){//code... ...

随机推荐

  1. Android - Builder模式

    https://github.com/simple-android-framework-exchange/android_design_patterns_analysis/tree/master/bu ...

  2. AutoFac简介

    在.NET上现在存在许多的依赖注入容器, 如:Castle Windsor.StructureMap.Autofac .Unity. 这里主要介绍一下Autofac,Autofac和其他容器的不同之处 ...

  3. java设计模式-----16、解释器模式

    概念: Interpreter模式也叫解释器模式,是行为模式之一,它是一种特殊的设计模式,它建立一个解释器,对于特定的计算机程序设计语言,用来解释预先定义的文法.简单地说,Interpreter模式是 ...

  4. node.js和JavaScript的关系

    node.js是一个基于 Chrome V8 引擎的 JavaScript 运行时环境. 一.类比JavaScript和java JavaScript java V8 JVM node.js JRE ...

  5. Code Signal_练习题_commonCharacterCount

    Given two strings, find the number of common characters between them. Example For s1 = "aabcc&q ...

  6. Fastify 系列教程二 (中间件、钩子函数和装饰器)

    Fastify 系列教程: Fastify 系列教程一 (路由和日志) Fastify 系列教程二 (中间件.钩子函数和装饰器) Fastify 系列教程三 (验证.序列化和生命周期) Fastify ...

  7. div实现返回符,倒三角,椭圆+小知识收集

    收集: 1,返回符(伪类元素): .back:before {content: "";width: .3rem;height: .3rem;border-left: .04rem ...

  8. Spring Boot—17MongoDB

    在MongoDB中插入如下的数据 db.baike.insert( { _id: 'freemark', desc: '新一代模板语言', tag: [ 'IT', '模板语言' ], comment ...

  9. Dialog中更新Activity的数据显示

    假设有一个activity,activity中有一个Button和一个TextView,点击按钮,弹出Dialog,对话框中有一个ListView,选中ListView中的某一项,关闭对话框,更新ac ...

  10. Linux 系统下 centOS 7 ipconfig 提示没有安装

    首先更正一下,在Linux系统下,查看IP地址,指令是ifconfig 没有root权限情况下,安装指令为 sudo yum -y install net-tool 有root权限的话,直接执行 yu ...