.selectBeautifyMainStyle{ color: #9fa0a0; font-size: 14px; font-family: "alegreya_sansthin"; text-transform: uppercase; width:415px; height:45px; line-height:45px; border:1px solid #D1D1D1; float:left; padding: 0 50px 0 10px; cursor:pointer; position: relative; margin-bottom: 25px; }
.selectBeautifyMainStyle span { display: block; position: absolute; top: 8px; right:; border-left: 1px solid #d1d1d1; width: 50px; height: 29px; background: url(../images/crlaine/selectopen.png) no-repeat 15px 10px;}
.selectBeautifyMenuStyle{ color: #005e79; font-size: 14px; font-family: "alegreya_sansthin"; text-transform: uppercase; width:415px; height:300px; border:1px solid #D1D1D1; padding:10px; position:absolute; z-index:; left:; top:45px; background:#FFF; overflow-y:auto; display:none;}
.selectBeautifyMenuStyle *{ padding:; margin:; }
.selectBeautifyMenuStyle ul{ list-style-type: none; }
.selectBeautifyMenuStyle li{ height: 35px; line-height: 35px; cursor: pointer; }
.selectBeautifyMenuStyle li.current-selected { color: #9fa0a0; }
.selectBeautifyMenuStyle li.bg-color { background-color: #f1f1f1; }
        // custom select-box function
function selectBeautify(id, mainStyle, menuStyle){
this.obj = $('#' + id);
this.mainStyle = mainStyle;
this.menuStyle = menuStyle;
this.run = function() {
this.obj.hide();
var cpObj = this.obj;
var mainHtml = '<div class="' + this.mainStyle + '">' + this.obj.find(":selected").html() + '<span></span></div>';
this.obj.after(mainHtml);
var menuHtml = '<div class="' + this.menuStyle + '"><ul>';
this.obj.find('option').each(function(){
menuHtml += "<li>"+$(this).html()+"</li>";
});
menuHtml += '</ul></div>';
this.obj.next().after(menuHtml); //Binding click event
this.obj.next().click(function(){
event.stopPropagation(); if($(this).next().is(':visible')){
$(this).next().slideUp(0);
return false;
}
$(this).parent().css({'position':'relative'});
$(this).next().slideDown();
$(this).next().css({'overflow-y':'auto'}); // current selected color
var currentText = $(this).text();
$(this).next().find('li').each(function() {
if ($(this).text() == currentText) {
$(this).addClass('current-selected').siblings().removeClass('current-selected');
}
}); //Binding the mouse events
// $(this).next().hover(function(){},function(){$(this).slideUp(0);});
$(document).click(function(){
cpObj.next().next().slideUp(0);
}); //Click select event binding
$(this).next().find('li').click(function(){
cpObj.next().html($(this).html() + '<span></span>');
cpObj.get(0).selectedIndex = $(this).index();
cpObj.find('option').eq($(this).index()).attr('selected', 'selected').siblings().removeAttr('selected');
cpObj.next().next().hide();
}); //mouse after li
$(this).next().find('li').hover(
function(){
$(this).addClass('bg-color');
},
function(){
$(this).removeClass('bg-color');
}
); });
}
}
var countrySelector = new selectBeautify('field69', 'selectBeautifyMainStyle', 'selectBeautifyMenuStyle');
countrySelector.run();

移出DIV后自动隐藏

        // custom select-box function
function selectBeautify(id, mainStyle, menuStyle){
this.obj = $('#' + id);
this.run = function() {
this.obj.hide();
var cpObj = this.obj; var mainHtml = '<div class="select-box"><div class="' + mainStyle + '">' + this.obj.find(":selected").html() + '<span></span></div>';
var menuHtml = '<div class="' + menuStyle + '"><ul>';
this.obj.find('option').each(function(){
menuHtml += '<li>'+$(this).html()+'</li>';
});
menuHtml += '</ul></div></div>';
this.obj.after(mainHtml + menuHtml); //Binding click event
this.obj.next().children('.' + mainStyle).click(function(){
if($(this).next().is(':visible')){
$(this).next().stop().slideUp(0);
return false;
} $(this).parent().css({'position':'relative'});
$(this).next().slideDown();
$(this).next().css({'overflow-y':'auto'}); // current selected color
var currentText = $(this).text();
$(this).next().find('li').each(function() {
if ($(this).text() == currentText) {
$(this).addClass('current-selected').siblings().removeClass('current-selected');
}
}); //Binding the mouse events
cpObj.next().hover(function(){},function(){$(this).children('.' + menuStyle).stop().slideUp(0);});
// $(this).next().hover(function(){},function(){$(this).slideUp(0);}); //Click select event binding
$(this).next().find('li').click(function(){
cpObj.next().children('.' + mainStyle).html($(this).html() + '<span></span>');
cpObj.get(0).selectedIndex = $(this).index();
cpObj.find('option').eq($(this).index()).attr('selected', 'selected').siblings().removeAttr('selected');
cpObj.next().children('.' + menuStyle).hide();
}); //mouse after li
$(this).next().find('li').hover(
function(){
$(this).addClass('bg-color');
},
function(){
$(this).removeClass('bg-color');
}
); });
}
}
var countrySelector = new selectBeautify('field69', 'selectBeautifyMainStyle', 'selectBeautifyMenuStyle');
countrySelector.run();

自定义 select 下拉菜单的更多相关文章

  1. [k]自定义样式下拉菜单

    自定义样式下拉菜单-1 <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> & ...

  2. CSS自定义select下拉选择框(不用其他标签模拟)

    今天群里有人问到怎么自定义select下拉选择框的样式,于是群里就展开了激烈的讨论,刚开始一直就是考虑怎样使用纯CSS实现,把浏览器默认的样式覆盖掉,但最后均因兼容问题处理不好而失败告终,最后的解决方 ...

  3. jQuery插件:模拟select下拉菜单

    没搞那么复杂,工作中,基本够用.. <!doctype html> <html> <head> <meta charset="utf-8" ...

  4. angular 实现自定义样式下拉菜单

    自己闲着没事写了一个自定义的下拉菜单希望和大家交流一下!望能和大神们成为朋友. 下面上代码: <!doctype html> <html lang="en" ng ...

  5. select 下拉菜单Option对象使用add(elements,index)方法动态添加

    原生js 的add函数为下拉菜单增加选项 1.object.add(oElement [, iIndex]) index 可选参数:指定元素放置所在的索引号,整形值.如果没有指定值,将添加到集合的最后 ...

  6. select下拉菜单反显不可改动,且submit能够提交数据

    首先通过后台funcA()将下拉菜单反显不可改动的数据response到disable.jsp页面,disable.jsp: <script> var data1=${result.obj ...

  7. 微信小程序之自定义select下拉选项框组件

    知识点:组件,animation,获取当前点击元素的索引与内容 微信小程序中没有select下拉选项框,所以只有自定义.自定义的话,可以选择模板的方式,也可以选择组件的方式来创建. 这次我选择了组件, ...

  8. 手写的select 下拉菜单

    我们在进行表单设计时,可能要用到select下拉选项控件,遗憾的是,IE浏览器默认的select控件外观非常丑陋,而且不能用样式来控制,不能在选项中添加图片等信息.今天我将通过实例来讲解如何用CSS和 ...

  9. WeChat-SmallProgram:自定义select下拉选项框组件

    1):创建组件所需的文件 2):自定义组件 CSS 及 JS 组件的wxml: <view class='com-selectBox'> <view class='com-sCont ...

随机推荐

  1. arm linux上的第一个应用程序 BOA移植

    1. 首先, linux在开发板上能跑起来了. 包括网络驱动也有了, ifconfig之后, 能看到在rcS里面设置的IP, 也能ping通windows主机了, 当然, 也要window关掉防火墙才 ...

  2. windows 下安装使用ipython

    转自:https://my.oschina.net/u/1431433/blog/189337 1. 下载安装Python 下载: python-3.3.3.amd64.msi (救在Python.o ...

  3. Spark Streaming Backpressure分析

    1.为什么引入Backpressure 默认情况下,Spark Streaming通过Receiver以生产者生产数据的速率接收数据,计算过程中会出现batch processing time > ...

  4. Android中的ContentValues用法

    ContentValues 和HashTable类似都是一种存储的机制 但是两者最大的区别就在于,contenvalues只能存储基本类型的数据,像string,int之类的,不能存储对象这种东西,而 ...

  5. 深入理解JavaScript Hijacking原理

    最近在整理关于JavaScript代码安全方面的资料,在查关于JavaScript Hijacking的资料时,发现关于它的中文资料很少,故特意整理一下. 一.JavaScript Hijacking ...

  6. 组合索引leaf 数据存储

    1 Z 2 X 3 U 4 T 5 G 6 F 7 C 8 B 9 A 1 A 2 B 3 C 4 D Oracle的索引是以平衡树的方式组织存储的:保存的是索引列的值,以及该行的rowid的一部分( ...

  7. Angular.js VS. Ember.js:谁将成为Web开发的新宠?

    这篇博文陈述的非常好,比较全面的剖析了Angular.js与Ember.js,下面的链接,供学习与参考: http://www.csdn.net/article/2013-09-09/2816880- ...

  8. Android添加标题进度条

    requestWindowFeaure(Window.FEATURE_PROGRESS); setProgressBarVisibility(true); 这两步必须在setContentView() ...

  9. socket中select的使用源码

    下面的代码来自IBM学习网站,是学习socket通信和select使用的一个很好的源码. server.c  服务器端 #include <stdio.h> #include <st ...

  10. js中的数据类型及其转换

    Js中的数据类型 Js中的数据类型一共有六种,即number,string,boolean,underfine,null,object. 一,number Number数据类型指的是数字,可以为整型, ...