.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. Highly divisible triangular number

    我的那个暴力求解,太耗时间了. 用了网上产的什么因式分解,质因数之类的.确实快!还是数学基础不行,只能知道大约. The sequence of triangle numbers is generat ...

  2. Android隐藏标题栏

    打开程序,在onCreate()方法中添加如下代码: protected void onCreate(Bundle savedInstanceState) { super.onCreate(saved ...

  3. Oracle extent

    extent 上的块 物理上绝对连续 多个连续的block组成一个extent 不连续怎么多块读? Oracle 给表分配的单位是extent 去做 全表扫描的时候 以块为单位,按照extent来读取 ...

  4. Best Time to Buy and Sell Stock IV 解答

    Question Say you have an array for which the ith element is the price of a given stock on day i. Des ...

  5. JDBC之ResultSet

    ResultSet is a interface More gnerally,ResultSet is a class involves a table returned by executeQuer ...

  6. 解析了grid2008的代码

    import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.L ...

  7. Myeclipse中java文件注释格式设置

    点击菜单windows->preferences,然后在左侧栏选择java ->Code Style -> CodeTemplates然后在右侧栏选择comments -> 依 ...

  8. [转载]SQL Server查找包含某关键字的存储过程3种方法

    存储过程都写在一个指定的表中了,我们只要使用like查询就可以实现查询当前这台SQL Server中所有存储过程中包括了指定关键字的存储过程并显示出来,下面一起来看看我总结了几条命令. 例子1 代码如 ...

  9. vue + vuex 表单处理

    使用场景:在一个表单中,各项数据提交后需要重置表单中各<input>元素的值为空. 组件中关联: <template> <el-form ref="form&q ...

  10. 你需要知道的九大排序算法【Python实现】之归并排序

    四.归并排序 基本思想:归并(Merge)排序法是将两个(或两个以上)有序表合并成一个新的有序表,即把待排序序列分为若干个子序列,每个子序列是有序的.然后再把有序子序列合并为整体有序序列.归并过程:比 ...