(function ($){
'use strict';
var g_id = 0;
var g_open_id = [];
$.fn.select3 = function () {
var _id = g_id++;
var _isShow = false;
var _this = $(this);
var _val = _this.children('option:selected').text();
var _w = _this.css('width');
var tpl = '<dl class="select2_wrap" style="width:'+_w+'"><dt class="open-dt" id="select2_title'+ _id +'" data-val=""><span>'+_val+'</span><i class="fa fa-sort-down"></i></dt>';
_this.children('option').each(function (){
tpl += '<dd style="display:none" data-val="'+ $(this).val() +'">' + $(this).text() + '</dd>';
});
tpl += '</dl>';
_this.hide().before(tpl); _this.bind('change', function () {
$('#select2_title').text($(this).val()).attr('data-val', $(this).val());
}); $('#select2_title'+_id).attr('data-val', $(this).val()); $('#select2_title'+_id).siblings().click(function () {
var text = $(this).text();
var _val = $(this).attr('data-val');
_this.val(_val);
$('#select2_title'+_id).attr('data-val',$(this).attr('data-val')).children('span').text(text);
$(this).parent('dl').children('dd').slideUp(200, function() {
$(this).siblings('dt').css({'borderBottom':'1px solid #ccc', 'border-bottom-right-radius':'5px', 'border-bottom-left-radius':'5px'});
}); _this.change();
}); $('#select2_title'+_id).click(function() {
$('dd').slideUp(100, function () {
$('dt[role-page]').attr('style', '');
});
var _id = $(this).attr('id');
g_open_id.push(_id);
$.each(g_open_id, function(i) {
if (g_open_id[i] != _id) {
$('#'+g_open_id[i]).siblings('dd').slideUp(200, function () {
$(this).siblings('dt').css({'borderBottom': '1px solid #ccc', 'border-bottom-right-radius': '5px', 'border-bottom-left-radius': '5px'});
});
delete g_open_id[i];
}
}); _isShow = $(this).siblings('dd').css('display') == 'none' ? false : true;
if (!_isShow) {
$(this).css({'borderBottom':'none', 'border-bottom-right-radius':'0', 'border-bottom-left-radius':'0'});
$(this).siblings('dd').slideDown(300);
}else{
$(this).siblings('dd').slideUp(200, function () {
$(this).siblings('dt').css({'borderBottom': '1px solid #ccc', 'border-bottom-right-radius': '5px', 'border-bottom-left-radius': '5px'});
});
}
}); $(window).click(function(e){
var pType = e.target.tagName;
var className = e.target.className; if (pType == 'I' || pType == 'SPAN') {
className = e.target.parentElement.className;
} if (className == 'open-dt') {
return;
} $('dd').slideUp(100, function () {
$('.select2_wrap').children('dt').css({'borderBottom': '1px solid #ccc', 'border-bottom-right-radius': '5px', 'border-bottom-left-radius': '5px'});
$('dt[role-page]').attr('style', '');
}); }); };
})(jQuery);

样式:

/* select3 style */
.select3-wrap{
display: inline-flex;
height: 30px;
width: 100%;
} .select2_wrap{
height: 30px;
line-height: 30px;
margin:;
padding:;
text-align:left;
display: inline-block;
font-size: 12px;
z-index:;
} .select2_wrap dt{
border:1px solid #ccc;
border-radius: 5px;
padding-left:10px;
font-weight: normal;
cursor:pointer;
overflow: hidden;
} .select2_wrap dt>i{
float:right;
margin-right: 10px;
margin-top:3px;
} .select2_wrap dd{
padding-left:10px;
background-color: #FFFFFF;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
} .select2_wrap dd:last-child{
border-bottom:1px solid #ccc;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
height: 35px;
} .select2_wrap dt, .select2_wrap dd{
height:30px;
line-height: 30px;
} .select2_wrap dd:hover{
background-color:#414C59;
color:white;
cursor:pointer;
} .hide {
display: none;
}

效果:

自定义Jquery 下拉框的更多相关文章

  1. jquery 下拉框 收藏

    jquery 下拉框  Query获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code. ...

  2. 带搜索框的jQuery下拉框插件

    由于下拉框的条数有几十个,于是打算找一个可以搜索查找功能的下拉框,刚开始在网上看了几个,都是有浏览器兼容性问题,后来看到这个“带搜索框的jQuery下拉框美化插件 searchable”,看演示代码简 ...

  3. jQuery下拉框操作系列$("option:selected",this) &&(锋利的jQuery)

    jQuery下拉框操作系列$("option:selected",this)  &&(锋利的jQuery) <!DOCTYPE html> <ht ...

  4. Ajax jQuery下拉框联动案例

    需求: 使用ajax和jQuery实现下拉框联动. 注意:需要加入jquery-2.1.1.min.js 前台 <!DOCTYPE html> <html> <head& ...

  5. 自定义SWT控件一之自定义单选下拉框

    一.自定义下拉控件 自定义的下拉框,是自定义样式的,其中的下拉框使用的是独立的window,非复选框的下拉框双击单机其它区域或选择完之后,独立window构成的下拉框会自动消失. package co ...

  6. jQuery下拉框插件8种效果

    jQuery自定义漂亮的下拉框插件8种效果 jquery美化选择器实例有:边框.下划线. 伸缩 .滑动. 覆盖. 旋转. 弹出层选择 .环形效果. 在线预览 <body class=" ...

  7. 自制Jquery下拉框插件

    (function ($) { $.fn.select3 = function (option) { $(this).each(function () { var _this = $(this); v ...

  8. Android自定义spinner下拉框实现的实现

    一:前言 本人参考博客:http://blog.csdn.net/jdsjlzx/article/details/41316417 最近在弄一个下拉框,发现Android自带的很难实现我的功能,于是去 ...

  9. jQuery下拉框扩展和美化插件Chosen

    Chosen 是一个支持jquery的select下拉框美化插件,它能让丑陋的.很长的select选择框变的更好看.更方便.不仅如此,它更扩展了select,增加了自动筛选的功能.它可对列表进行分组, ...

随机推荐

  1. 各种java生成word解决方案的优缺点对比

    解决方案 优点 缺点 Jacob 功能强大 直接调用VBA接口,程序异常复杂:服务器必须是:windows系统+安装Office:服务器端自动化com接口容易产生死进程造成服务器宕机 Apache P ...

  2. MySQL_详细基本操作命令

    mysql 修改新密码:use mysql:update user set password='新密码' where user='用户名':flush privileges:  更新权限 增加新用户: ...

  3. E20170510-hm

    prototype  n.     原型,雏形,蓝本; omit (omitted)  vt.     省略; 遗漏; autonomous  adj.     自治的; 有自主权的; fold   ...

  4. Ruby基本语法

    更新: 2017/06/09 更新: 2017/06/20 cattr_accessor定义类变量,相当于@@ 更新: 2017/06/23 生成类的实例 更新: 2017/06/24 补充loop的 ...

  5. 模板 - 字符串 - Manacher

    求最长回文子串. #include<bits/stdc++.h> using namespace std; #define ll long long ; ]; ]; int Manache ...

  6. Codeforces - 814B - An express train to reveries - 构造

    http://codeforces.com/problemset/problem/814/B 构造题烦死人,一开始我还记录一大堆信息来构造p数列,其实因为s数列只有两项相等,也正好缺了一项,那就把两种 ...

  7. POJ2370【水题】

    //#include <bits/stdc++.h> #include<iostream> #include<string.h> #include<cstdi ...

  8. Template Code 无法使用 this.Host 报错

    问题显示: Error 6 Compiling transformation: 'Microsoft.VisualStudio.TextTemplatingBED07DAE3B6FD53FA94701 ...

  9. CentOS 7.6 最小安装 ifconfig command not found 及 yum 不可用的解决办法

    问题描述 下载的是 CentOS 7.6 Everything 版本,在 VMware 12 上安装时软件选择“最小安装”后,输入 ifconfig 命令提示: bash ifconfig comma ...

  10. EOS:dfuse stream 保证不会错过一个心跳

    强大的 dfuse history API 给我们带来了高效的链数据获取途径,让我们的 dapp 在用户体验上了一个台阶. 官方示例 不会错过一个心跳 代码分析 函数 pendingActions 待 ...