自定义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,增加了自动筛选的功能.它可对列表进行分组, ...
随机推荐
- 推箱子 hdu1254
推箱子 1 http://acm.hdu.edu.cn/showproblem.php?pid=1254 推箱子 2 http://acm.hzau.edu.cn/problem.php?id=1 ...
- OCCI编程接口介绍
OCCI简介 Oracle® C++ Call Interface (OCCI) 是一套应用程序编程接口,它允许C++程序与一个或者多个Oracle数据库进行交互.OCCI给予你强大的数据库操作能力, ...
- ML 徒手系列说明
徒手系列正确打开方式: 1.徒手撸公式 2.徒手撸代码
- Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.mao.PersonSet
转自:https://blog.csdn.net/vipmao/article/details/51334743
- pl/sql 远程连接oracl服务器方法
在Oracle/network/admin中的tnsnames.ora中添加对应的如下代码: LISTENER_ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = ...
- Mysql基础调优
mysql基础的优化方式 1.利用索引加快查询速度 2.利用查询缓存或者旁挂式缓存,提高访问速度 缓存:k/v key:查询语句的hash值 value:查询语句的执行结果 哪些查询可能不会被缓存? ...
- Android—— ListView 的简单用法及定制ListView界面
一.ListView的简单用法 2. 训练目标 1) 掌握 ListView 控件的使用 2) 掌握 Adapter 桥梁的作用 实现步骤: 1)首先新建一个项目, 并让ADT 自动帮我们创建好活动. ...
- XTU1267:Highway(LCA+树的直径)
传送门 题意 有n个小镇,Bobo想要建造n-1条边,并且如果在u到v建边,那么花费是u到v的最短路长度(原图),问你最大的花费. 分析 比赛的时候没做出来,QAQ 我们首先要找到树的直径起点和终点, ...
- DFS系列 POJ(自认为的讲解)
C - Sum It Up POJ1564 题意: 给你一个N,然后给你一堆数The numbers in each list appear in nonincreasing order, and t ...
- bzoj 3262 陌上花开 【CDQ分治】
三维偏序 首先把所有花按 x一序,y二序,z三序 排序,然后去重,con记录同样的花的个数,然后进行cdq 现在假设有[l.r]区间,其中[l,mid] [mid+1,r],已经递归处理完毕.我们把区 ...