search
HomeWeb Front-endJS TutorialWeb page SELECT drop-down box beautification code based on jquery_jquery

1. Solved the problem that some select beautification codes could not trigger the onchange event of the original select control.
2. Allow multiple calls to $("...").selectCss() to solve the problem that Select options cannot be synchronized after they are updated.

The usage method is as follows:

Copy the code The code is as follows:





Untitled Document











Main file Including selectCss.css and selectCss.js
selectCss.js file code:
Copy code The code is as follows:

(function($){
function hideOptions(speed){
if(speed.data){speed=speed.data}
if($(document).data("nowselectoptions"))
{
$($(document).data("nowselectoptions")).slideUp(speed);
$($(document).data("nowselectoptions")).prev("div").removeClass("tag_select_open");
$(document).data("nowselectoptions",null);
$(document).unbind("click",hideOptions);
$(document).unbind("keyup",hideOptionsOnEscKey);
}
}
function hideOptionsOnEscKey(e){
var myEvent = e || window.event;
var keyCode = myEvent.keyCode;
if(keyCode==27)hideOptions(e.data);
}
function showOptions(speed){
$(document).bind("click",speed,hideOptions);
$(document).bind("keyup",speed,hideOptionsOnEscKey);
$($(document).data("nowselectoptions")).slideDown(speed);
$($(document).data("nowselectoptions")).prev("div").addClass("tag_select_open");
}

$.fn.selectCss=function(_speed){
$(this).each(function(){
var speed=_speed||"fast";
if($(this).data("cssobj")){
$($(this).data("cssobj")).remove();
}
$(this).hide();
var divselect = $("
").insertAfter(this).addClass("tag_select");
$(this).data("cssobj",divselect);
var divoptions = $("
    ").insertAfter(divselect).addClass("tag_options").hide();
    divselect.click(function(e){
    if($($(document).data("nowselectoptions")).get(0) != $(this).next("ul").get(0)){
    hideOptions(speed);
    }
    if(!$(this).next("ul").is(":visible"))
    {
    e.stopPropagation();
    $(document).data("nowselectoptions",$(this).next("ul"));
    showOptions(speed);
    }
    });
    divselect.hover(function(){
    $(this).addClass("tag_select_hover");
    }
    ,
    function(){
    $(this).removeClass("tag_select_hover");
    });
    $(this).change(function(){
    $(this).nextAll("ul").children("li:eq(" $(this)[0].selectedIndex ")").addClass("open_selected").siblings().removeClass("open_selected");
    $(this).next("div").html($(this).children("option:eq(" $(this)[0].selectedIndex ")").text());
    });
    $(this).children("option").each(function(i){
    var lioption= $("
  • ").html($(this).text()).attr("title",$(this).attr("title")).appendTo(divoptions);
    if($(this).attr("selected")){
    lioption.addClass("open_selected");
    divselect.html($(this).text());
    }
    lioption.data("option",this);
    lioption.click(function(){
    lioption.data("option").selected=true;
    $(lioption.data("option")).trigger("change",true)
    });
    lioption.hover(
    function(){$(this).addClass("open_hover");},
    function(){ $(this).removeClass("open_hover"); }
    );
    });
    });
    }
    })(jQuery);

  • selectCss.Css 文件代码:
    复制代码 代码如下:

    .tag_select{display:block;color:#000;width:179px;height:23px;background:transparent url("images/index_22.jpg") no-repeat 0 0;padding:0 10px;line-height:23px; color:#7D7D7D; font-size:12px; cursor:pointer}
    .tag_select_hover{ color:#ff0000; background:transparent url("selectbg.jpg") no-repeat 0 0; }
    .tag_select_open{ color:#0000ff; background:transparent url("selectbg.jpg") no-repeat 0 0;}
    ul.tag_options{position:absolute;margin:0;list-style:none;background:#fff;padding:0 0 1px;margin:0;width:162px ; height:100px; overflow:hidden; overflow-y:auto; font-size:12px; margin-left:10px; cursor:pointer; z-index:1000 }
    ul.tag_options li{background:#fff; display:block;width:140px;padding:0 10px;height:20px;text-decoration:none;line-height:20px;color:#000; font-weight:normal; font-size:12px}
    ul.tag_options li.open_hover{background:#0000ff;color:#000; font-weight:normal; font-size:12px}
    ul.tag_options li.open_selected{background:#ccc; font-size:12px;font-weight:bold; }

    selectbg.jpg 图片:
    Web page SELECT drop-down box beautification code based on jquery_jquery
    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    使用golang进行Select Channels Go并发式编程的异步处理方法使用golang进行Select Channels Go并发式编程的异步处理方法Sep 28, 2023 pm 05:27 PM

    使用golang进行SelectChannelsGo并发式编程的异步处理方法引言:并发式编程是现代软件开发中的一个重要领域,它可以有效地提高应用程序的性能和响应能力。在Go语言中,使用Channels和Select语句可以简单而高效地实现并发编程。本文将介绍如何使用golang进行SelectChannelsGo并发式编程的异步处理方法,并提供具体的

    jquery如何隐藏select元素jquery如何隐藏select元素Aug 15, 2023 pm 01:56 PM

    jquery隐藏select元素的方法:1、hide()方法,在HTML页面中引入jQuery库,可以使用不同选择器来隐藏select元素,ID选择器将selectId替换为你实际使用的select元素的ID;2、css()方法,使用ID选择器选择需要隐藏的select元素,使用css()方法将display属性设置为none,并将selectId替换为select元素的ID。

    jQuery中如何实现select元素的改变事件绑定jQuery中如何实现select元素的改变事件绑定Feb 23, 2024 pm 01:12 PM

    jQuery是一个流行的JavaScript库,可以用来简化DOM操作、事件处理、动画效果等。在web开发中,经常会遇到需要对select元素进行改变事件绑定的情况。本文将介绍如何使用jQuery实现对select元素改变事件的绑定,并提供具体的代码示例。首先,我们需要使用标签来创建一个包含选项的下拉菜单:

    如何在Vue中实现多选下拉框如何在Vue中实现多选下拉框Nov 07, 2023 pm 02:09 PM

    如何在Vue中实现多选下拉框在Vue开发中,下拉框是常见的表单组件之一。通常情况下,我们都使用单选下拉框来选择一个选项。但是,有时候我们需要实现多选下拉框,以便用户可以同时选择多个选项。在本文中,我们将介绍如何在Vue中实现多选下拉框,并提供具体的代码示例。一、使用ElementUI组件库ElementUI是一套基于Vue的桌面端组件库,提供了丰富的UI

    linux要用select的原因是什么linux要用select的原因是什么May 19, 2023 pm 03:07 PM

    因为select可以使开发者在同时等待多个文件缓冲区,可减少IO等待的时间,能够提高进程的IO效率。select()函数是IO多路复用的函数,允许程序监视多个文件描述符,等待所监视的一个或者多个文件描述符变为“准备好”的状态;所谓的”准备好“状态是指:文件描述符不再是阻塞状态,可以用于某类IO操作了,包括可读,可写,发生异常三种。select是一个计算机函数,位于头文件#include。该函数用于监视文件描述符的变化情况——读写或是异常。1.select函数介绍select函数是IO多路复用的函

    mysql的select语法怎么使用mysql的select语法怎么使用Jun 01, 2023 pm 07:37 PM

    1、SQL语句中的关键词对大小写不敏感,SELECT等效于SELECT,FROM等效于from。2、从users表中选择所有列的,可以用符号*代替列的名称。语法--这是注释--从FEOM指定的[表中],查询出[所有的]数据.*表示[所有列]SELECT*FROM--通过从FROM从指定的[表中],查询出指定列名称(字段)的数据SELECT列名称FROM表名称实例--注意:多个列之间,使用英文的逗号来分隔selectusername,passwordfrom

    通过golang实现Select Channels Go并发式编程的性能优化通过golang实现Select Channels Go并发式编程的性能优化Sep 27, 2023 pm 01:09 PM

    通过golang实现SelectChannelsGo并发式编程的性能优化在Go语言中,使用goroutine和channel实现并发编程是非常常见的。而在处理多个channel的情况下,我们通常会使用select语句来进行多路复用。但是,在大规模并发的情况下,使用select语句可能会导致性能下降。在本文中,我们将介绍一些通过golang实现select

    使用golang实现可靠性和鲁棒性的Select Channels Go并发式编程使用golang实现可靠性和鲁棒性的Select Channels Go并发式编程Sep 28, 2023 pm 05:37 PM

    使用Golang实现可靠性和鲁棒性的SelectChannelsGo并发式编程引言:在现代软件开发中,并发性已经成为了一个非常重要的主题。使用并发编程可以使得程序更具有响应性、更高效地利用计算资源,并且能够更好地处理大规模的并行计算任务。Golang是一种非常强大的并发编程语言,它通过go协程和channel机制,提供了一种简单而有效的方式来实现并发编程

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    Repo: How To Revive Teammates
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island Adventure: How To Get Giant Seeds
    3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Dreamweaver Mac version

    Dreamweaver Mac version

    Visual web development tools

    Safe Exam Browser

    Safe Exam Browser

    Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    SAP NetWeaver Server Adapter for Eclipse

    SAP NetWeaver Server Adapter for Eclipse

    Integrate Eclipse with SAP NetWeaver application server.

    SublimeText3 English version

    SublimeText3 English version

    Recommended: Win version, supports code prompts!