.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. Qweb报表中的Reload from Attachment参数

    通过继承的方式修改了Qweb报表却发现没有生效,经查,其原因在于报表的设置中勾选了 Reload from Attachment 选项. 将本选项取消选中即可生效.

  2. iOS推送 再备

    这是一篇编译的文章,内容均出自Parse.com的iOS开发教程,同时作者还提供了视频讲解.本文将带领开发者一步一步向着iOS推送通知的深处探寻,掌握如何配置iOS推送通知的奥义. 介绍一点点背景资料 ...

  3. KesionCMS V6.5后台拿SHELL方法

    Title:KesionCMS V6.5后台拿SHELL方法  --2011-03-29 00:21 最近弄一个站点,是KesionCMS V6.5的WEB系统,试了下后台拿webshell方法,记下 ...

  4. JAVA构造方法,继承关系和SUPER关键字

    SUPER可调用父类的构造方法,但要注意默认调用和参数调用. 同时,在继承类时,可以用SUPER调用其它非构造方法哟. class Test extends Object{ public Test() ...

  5. PHP上传文件出现文件名被截掉第一个字符的问题

    最近用PHP做了一个简单的上传功能,结果出现了一个意想不到的问题.我上传的文件,在获取$_FILES的时候发现文件名的第一个字符被截掉了,因为最开始上传的一直是数字或者字母为名称的文档,也没有太在意这 ...

  6. poj 2287 动态规划

    用贪心简单证明之后就是一个从两头取的动态规划 #include <iostream> #include <cstring> #include <cstdio> #i ...

  7. makefile工程管理

    个人理解吧,makefile就是写一个指定格式的文件,将一系列的编译.链接.转换等操作打包在一起,方便以后一键生成可执行的二进制文件而产生的.下面记录一下这种文件的写法,方便以后忘了来查询. make ...

  8. HDU_1239——再次调用外星智慧

    Problem Description A message from humans to extraterrestrial intelligence was sent through the Arec ...

  9. HDU_2028——求多个数的最小公倍数

    Problem Description 求n个数的最小公倍数.   Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数.   Output 为每组测试数据输出它们的最 ...

  10. HDU_2027——统计元音

    Problem Description 统计每个元音字母在字符串中出现的次数.   Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串.   Output ...