• 微软原版系统

  • 一键重装系统

  • 纯净系统

  • 在线技术客服

魔法猪系统重装大师 一键在线制作启动 U 盘 PE 系统 用一键重装的魔法拯救失去灵魂的系统
当前位置:首页 > 教程 > 电脑教程

网页SELECT下拉框美化JQUERY插件

时间:2015年04月02日 15:38:23    来源:魔法猪系统重装大师官网    人气:9752

最近为公司的网页制做部,开发了一个用于美化网页上select 下拉框的JQUERY插件,拿来与大家分享。
1.解决了有些select 美化代码,无法触发原有select 控件的onchange 事件问题。

2.允许多次调用 $("...").selectCss(),以解决Select的options更新后无法同步的问题。

使用方法如下:
代码




无标题文档












主要文件包括 selectCss.css 和 selectCss.js
selectCss.js 文件代码:
(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 图片:

    网页,SELECT,下拉,框,美化,JQUERY,插件,最近
    栏目:电脑教程 阅读:1000 2023/12/27
    Win7教程 更多>>
    U盘教程 更多>>
    Win10教程 更多>>
    魔法猪学院 更多>>

    Copyright © 2015-2023 魔法猪 魔法猪系统重装大师

    本站发布的系统仅为个人学习测试使用,请在下载后24小时内删除,不得用于任何商业用途,否则后果自负,请支持购买微软正版软件。

    在线客服 查看微信 返回顶部