Home Web Front-end JS Tutorial Web page SELECT drop-down box beautification code based on jquery_jquery

Web page SELECT drop-down box beautification code based on jquery_jquery

May 16, 2016 pm 06:17 PM
select drop down box

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 of this Website
    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

    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

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Article

    Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    Nordhold: Fusion System, Explained
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Hot Topics

    Java Tutorial
    1664
    14
    PHP Tutorial
    1269
    29
    C# Tutorial
    1248
    24
    How to hide the select element in jquery How to hide the select element in jquery Aug 15, 2023 pm 01:56 PM

    How to hide the select element in jquery: 1. hide() method, introduce the jQuery library into the HTML page, you can use different selectors to hide the select element, the ID selector replaces the selectId with the ID of the select element you actually use; 2. css() method, use the ID selector to select the select element that needs to be hidden, use the css() method to set the display attribute to none, and replace selectId with the ID of the select element.

    Asynchronous processing method of Select Channels Go concurrent programming using golang Asynchronous processing method of Select Channels Go concurrent programming using golang Sep 28, 2023 pm 05:27 PM

    Asynchronous processing method of SelectChannelsGo concurrent programming using golang Introduction: Concurrent programming is an important area in modern software development, which can effectively improve the performance and responsiveness of applications. In the Go language, concurrent programming can be implemented simply and efficiently using Channels and Select statements. This article will introduce how to use golang for asynchronous processing methods of SelectChannelsGo concurrent programming, and provide specific

    How to implement a multi-select drop-down box in Vue How to implement a multi-select drop-down box in Vue Nov 07, 2023 pm 02:09 PM

    How to implement a multi-select drop-down box in Vue. In Vue development, the drop-down box is one of the common form components. Normally, we use radio drop-down boxes to select an option. However, sometimes we need to implement a multi-select drop-down box so that users can select multiple options at the same time. In this article, we will introduce how to implement a multi-select drop-down box in Vue and provide specific code examples. 1. Use the ElementUI component library. ElementUI is a desktop component library based on Vue, which provides a rich UI.

    How to implement change event binding of select elements in jQuery How to implement change event binding of select elements in jQuery Feb 23, 2024 pm 01:12 PM

    jQuery is a popular JavaScript library that can be used to simplify DOM manipulation, event handling, animation effects, etc. In web development, we often encounter situations where we need to change event binding on select elements. This article will introduce how to use jQuery to bind select element change events, and provide specific code examples. First, we need to create a dropdown menu with options using labels:

    What is the reason why Linux uses select? What is the reason why Linux uses select? May 19, 2023 pm 03:07 PM

    Because select allows developers to wait for multiple file buffers at the same time, it can reduce IO waiting time and improve the IO efficiency of the process. The select() function is an IO multiplexing function that allows the program to monitor multiple file descriptors and wait for one or more of the monitored file descriptors to become "ready"; the so-called "ready" state is Refers to: the file descriptor is no longer blocked and can be used for certain types of IO operations, including readable, writable, and exceptions. select is a computer function located in the header file #include. This function is used to monitor file descriptor changes—reading, writing, or exceptions. 1. Introduction to the select function. The select function is an IO multiplexing function.

    Implement Select Channels Go concurrent programming performance optimization through golang Implement Select Channels Go concurrent programming performance optimization through golang Sep 27, 2023 pm 01:09 PM

    Implementing SelectChannels through golang Performance optimization of Go concurrent programming In the Go language, it is very common to use goroutine and channel to implement concurrent programming. When dealing with multiple channels, we usually use select statements for multiplexing. However, in the case of large-scale concurrency, using select statements may cause performance degradation. In this article, we will introduce some implementations of select through golang

    How to use the select syntax of mysql How to use the select syntax of mysql Jun 01, 2023 pm 07:37 PM

    1. Keywords in SQL statements are not case-sensitive. SELECT is equivalent to SELECT, and FROM is equivalent to from. 2. To select all columns from the users table, you can use the symbol * to replace the column name. Syntax--this is a comment--query out [all] data from the [table] specified by FEOM. * means [all columns] SELECT*FROM--query out the specified data from the specified [table] from FROM Data of column name (field) SELECT column name FROM table name instance--Note: Use English commas to separate multiple columns selectusername, passwordfrom

    Select Channels Go concurrent programming for reliability and robustness using golang Select Channels Go concurrent programming for reliability and robustness using golang Sep 28, 2023 pm 05:37 PM

    SelectChannels for Reliability and Robustness Using Golang Introduction to Concurrent Programming: In modern software development, concurrency has become a very important topic. Using concurrent programming can make programs more responsive, utilize computing resources more efficiently, and be better able to handle large-scale parallel computing tasks. Golang is a very powerful concurrent programming language. It provides a simple and effective way to implement concurrent programming through go coroutines and channel mechanisms.

    See all articles