自定义Jquery 下拉框
(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 下拉框的更多相关文章
- jquery 下拉框 收藏
jquery 下拉框 Query获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code. ...
- 带搜索框的jQuery下拉框插件
由于下拉框的条数有几十个,于是打算找一个可以搜索查找功能的下拉框,刚开始在网上看了几个,都是有浏览器兼容性问题,后来看到这个“带搜索框的jQuery下拉框美化插件 searchable”,看演示代码简 ...
- jQuery下拉框操作系列$("option:selected",this) &&(锋利的jQuery)
jQuery下拉框操作系列$("option:selected",this) &&(锋利的jQuery) <!DOCTYPE html> <ht ...
- Ajax jQuery下拉框联动案例
需求: 使用ajax和jQuery实现下拉框联动. 注意:需要加入jquery-2.1.1.min.js 前台 <!DOCTYPE html> <html> <head& ...
- 自定义SWT控件一之自定义单选下拉框
一.自定义下拉控件 自定义的下拉框,是自定义样式的,其中的下拉框使用的是独立的window,非复选框的下拉框双击单机其它区域或选择完之后,独立window构成的下拉框会自动消失. package co ...
- jQuery下拉框插件8种效果
jQuery自定义漂亮的下拉框插件8种效果 jquery美化选择器实例有:边框.下划线. 伸缩 .滑动. 覆盖. 旋转. 弹出层选择 .环形效果. 在线预览 <body class=" ...
- 自制Jquery下拉框插件
(function ($) { $.fn.select3 = function (option) { $(this).each(function () { var _this = $(this); v ...
- Android自定义spinner下拉框实现的实现
一:前言 本人参考博客:http://blog.csdn.net/jdsjlzx/article/details/41316417 最近在弄一个下拉框,发现Android自带的很难实现我的功能,于是去 ...
- jQuery下拉框扩展和美化插件Chosen
Chosen 是一个支持jquery的select下拉框美化插件,它能让丑陋的.很长的select选择框变的更好看.更方便.不仅如此,它更扩展了select,增加了自动筛选的功能.它可对列表进行分组, ...
随机推荐
- Codeforces-914F Substrings in a String (Bitset求T串中S串出现次数)
之前有过区域赛,简化版问题: 给定一个小写字符组成的字符串S,(|S|<1e5,下标从1开始),现在有Q种操作,对于每个操作Q(Q<=1e5),输入opt, 如果opt==1,输入x,c, ...
- [Selenium] 操作新弹出窗口之验证标题和内容
1)验证标题 package com.learningselenium.normalwebdriver; import static org.junit.Assert.*; import java.u ...
- BZOJ_3073_[Pa2011]Journeys_线段树优化建图+BFS
BZOJ_3073_[Pa2011]Journeys_线段树优化建图+BFS Description Seter建造了一个很大的星球,他准备建造N个国家和无数双向道路.N个国家很快建造好了,用1..N ...
- DP专辑之线性DP
POJ1390 题目链接:http://poj.org/problem?id=1390 分类:记忆化搜索 dp[i][j][k] 表示,从i到j块且j后面有k块与第j块的颜色一样.dp[l][r][k ...
- Video.js事件
Home 膘叔 » Archives 文章: 备份一个video的JS [打印] 分类: Javascript 作者: gouki 2012-02-16 17:58 备份一个JS,不是为了代码很优秀, ...
- mounted
注意 mounted 不会承诺所有的子组件也都一起被挂载.如果你希望等到整个视图都渲染完毕,可以用 vm.$nextTick 替换掉 mounted: mounted: function () { t ...
- 重新安装VMware10提示"The Msi '' Failed"问题解决方案
想把虚拟机软件升级以下,没想到卸载的时候不干净,再安装的时候总提示让我先卸载旧版本但实际上旧版本已经卸载过了,这里又没法再卸载一次,所以就提示”The MSI '' failed“ 显然,安装程序还是 ...
- jsp实现文件上传(一)用jspSmartUpload组件实现文件上传
java类(ImageUtil.java) import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import ...
- P5169 xtq的异或和(FWT+线性基)
传送门 我咋感觉我学啥都是白学-- 首先可以参考一下这一题,从中我们可以知道只要知道两点间任意一条路径以及整个图里所有环的线性基,就可以得知这两个点之间的所有路径的异或和 然而我好像并不会求线性基能张 ...
- SVG新手入门
特点 矢量图 属性:形状的参数(都没有单位) 添加事件跟html一样 修改样式跟html一样 属性操作: setAttribute/getAttribute 图形 <svg width=&quo ...