自定义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,增加了自动筛选的功能.它可对列表进行分组, ...
随机推荐
- hdu2544 迪杰斯特拉题目优化
点击打开题目链接 迪杰斯特拉的用法不多讲,详见 点击打开链接 . 下面两个代码: 这个是用邻接矩阵存图的迪杰斯特拉. #include<stdio.h> int main() { int ...
- hadoop源码剖析--$HADOOP_HOME/bin/hadoop脚本文件分析
1. $HADOOP_HOME/bin/ hadoop #!/usr/bin/env bash# Licensed to the Apache Software Foundation (ASF) un ...
- js获取form的方法
先来看下面代码: ? <html> <head> <scirpy> window.onload=function(){ var f1=document.f1; ...
- [Selenium] 测试机器上安装了多个Firefox,如何指定运行哪一个?
可通过FirefoxBinary 来指定运行某个路径下的Firefox, 示例代码如下: public class testFirefoxBinary{ public static void main ...
- 「LuoguP4779」 【模板】单源最短路径(标准版)
Description 2018 年 7 月 19 日,某位同学在 NOI Day 1 T1 归程 一题里非常熟练地使用了一个广为人知的算法求最短路. 然后呢? 100→60: Ag→Cu: 最终,他 ...
- bzoj5063
平衡树 6个操作做完当然GG了,其实只有两个操作,翻转[A+1,A+B],把这个区间放到C的后面,那么就是基本splay操作了,可是好久没打,又GG了,splay函数写错了... #include&l ...
- Socket教程
Socket网络编程学习笔记(6):使用线程池提高性能 Socket网络编程学习笔记(5):发送和接收实体类数据 Socket网络编程学习笔记(4):TCP消息边界处理 Socket网络 ...
- docker容器管理基础
1.命令: docker info #查看服务器上docker详细信息 docker search #搜索镜像 docker image pull nginx:1.14-alpine #下载一个镜像 ...
- 51nod1127【尺取】
思路: 尺取,写挫了,debug了半天. #include <bits/stdc++.h> using namespace std; typedef long long LL; const ...
- 51nod 1092【区间dp】
思路: 简单的区间dp,从小区间到大区间,随便写. 还有一种是那啥,n-LCS...具体不说了,赶时间)))= =. #include <stdio.h> #include <str ...