`

Jquery ul下拉框效果

阅读更多

  html select下拉框样式在网站开发时很难控制,网上找的模仿下拉框效果代码太长而且和Jquery有这严重的冲突,于是自己写了一个ul下拉框效果,代码很短也很简单。

 

  select.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="Css/DropDownStyle.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Js/DropDown.js" type="text/javascript"></script>
</head>
<body>
 <ul id="uboxstyle" style=" float:left; margin-top:6px; position:relative;">
              <li class="uboxstyle_Selected">查商品</li>
              <li class="uboxstyle5">查商品</li>
              <li class="uboxstyle5">查商家</li>
              <li class="uboxstyle5">查服务</li>
              <li class="uboxstyle4">查人员</li>
              </ul>
</body>
</html>

 

 

  DropDown.js

/// <reference path="../Scripts/jquery-1.4.1-vsdoc.js" />

 

//缺少鼠标离开,下拉框自动合拢写法

//搜索下列
$(function () {
    li_hide();
    //鼠标移到移开交替显示
    $("#uboxstyle>li").first().hover(function () {
        DropDownStyle($(this), "uboxstyle_Selecting");
    }, function () {
        DropDownStyle($(this), "uboxstyle_Selected");
    });

    //展开下拉控件的样式
    $("#uboxstyle>li").first().click(function () {
        DropDownStyle($(this), "uboxstyle_Select");
        li_ctrl();
    });

    //在下拉控件中操作
    $("#uboxstyle>li").each(function () {
        if ($("#uboxstyle>li").index($(this)) > 0) {
            //鼠标移动
            $(this).hover(function () {
                DropDownStyle($(this), "uboxstyle6");
            }, function () {
                DropDownStyle($(this), "uboxstyle5");
            });
            //鼠标点击
            $(this).click(function () {
                $("#uboxstyle>li:eq(0)").html($(this).html());
                li_hide();
            });
        }
    });

    //为控件设置样式
    function DropDownStyle($ctrl, styleName) {
        $ctrl.attr("className", styleName);
    }

    //显示
    function li_hide() {
        $("#uboxstyle>li:gt(0)").hide();
    }

    //控制显示隐藏
    function li_ctrl() {
        if ($("#uboxstyle>li:eq(1)").is(":hidden")) {
            li_show();
        }
        else {
            li_hide();
            DropDownStyle($("#uboxstyle>li:eq(0)"), "uboxstyle_Selecting");
        }
    }

    //隐藏
    function li_show() {
        $("#uboxstyle>li:gt(0)").show();
    }
});

 

  DropDownStyle.css

body
{
    padding:0px;
    margin:0px;
}

 

/* 选项卡搜索 开始*/
#uboxstyle{width:118px; height:30px}
.uboxstyle_Selected{
    display:block;
    color:#447004;
    width:98px;
    height:30px;
    padding:0px 10px;
    line-height:30px;
    background-color: transparent;
    background-image: url(../Images/home_search1.gif);
    background-repeat: no-repeat;
    background-position: 0 0;
     text-align:center;
     line-height:30px;
     cursor:hand;
}
.uboxstyle_Selecting{
    display:block;
    color:#447004;
    width:98px;
    height:30px;
    padding:0px 10px;
    line-height:30px;
    font-size:14px;
    background-color: transparent;
    background-image: url(../Images/home_search1.gif);
    background-repeat: no-repeat;
    background-position: 0px -30px;
     text-align:center;
     line-height:30px;
     cursor:hand;
}
.uboxstyle_Select{
    display:block;
    color:#447004;
    width:98px;
    padding:0 10px;
    line-height:30px;
    font-size:14px;
    background-image: url(../Images/home_search1.gif);
    background-repeat: no-repeat;
    background-position: 0 0;
     text-align:center;
     line-height:30px;
}

.uboxstyle5:hover {
    display:block;
    width:96px;
    height:30px;
    padding:0 10px;
    text-decoration:none;
    line-height:30px;
    font-size:14px;
    color:#FFF;
    background-color: #88C302;
    text-align:center;
    line-height:30px;
    cursor:hand;
    border-right-width: 1px;
    border-left-width: 1px;
    border-right-style: solid;
    border-left-style: solid;
    border-right-color: #d0d0d0;
    border-left-color: #d0d0d0;
}
.uboxstyle4{
    display:block;
    width:116px;
    height:30px;
    text-decoration:none;
    line-height:30px;
    font-size:14px;
    color:#447004;
    background-color: #ffffff;
    text-align:center;
    line-height:30px;
    cursor:hand;
    border-right-width: 1px;
    border-left-width: 1px;
    border-right-style: solid;
    border-left-style: solid;
    border-right-color: #d0d0d0;
    border-left-color: #d0d0d0;
    border-bottom-width: 1px;
    border-bottom-style: solid;
    border-bottom-color: #d0d0d0;
}

.uboxstyle4:hover {
    display:block;
    width:96px;
    height:30px;
    padding:0 10px;
    text-decoration:none;
    line-height:30px;
    font-size:14px;
    color:#FFF;
    background-color: #88C302;
    text-align:center;
    line-height:30px;
    cursor:hand;
    border-right-width: 1px;
    border-left-width: 1px;
    border-right-style: solid;
    border-left-style: solid;
    border-right-color: #d0d0d0;
    border-left-color: #d0d0d0;
}
.uboxstyle5{
    display:block;
    width:96px;
    height:30px;
    padding:0 10px;
    text-decoration:none;
    line-height:30px;
    font-size:14px;
    color:#447004;
    background-color: #ffffff;
    text-align:center;
    line-height:30px;
    cursor:hand;
    border-right-width: 1px;
    border-left-width: 1px;
    border-right-style: solid;
    border-left-style: solid;
    border-right-color: #d0d0d0;
    border-left-color: #d0d0d0;
}
.uboxstyle6{
    color:#ffffff;
    background-color: transparent;
    background-image: url(../Images/home_search1.gif);
    background-repeat: no-repeat;
        background-position: 0px -90px;
     width:118px;
     height:30px;
     text-align:center;
     line-height:32px;
     cursor:hand;
}
.uboxstyle7{
    background-image: url(../Images/home_search1.gif);
    background-repeat: no-repeat;
        background-position: 0px -120px;
    color:#fff
}

/* 选项卡搜索 结束*/

分享到:
评论

相关推荐

    jQuery结合UL标签下拉框美化特效代码

    JQuery结合UL标签下拉框美化是一款没有使用到select标签,由ul标签和input标签组合,点击下拉项后能获取到值。

    jQuery结合UL标签下拉框美化.zip

    JQuery结合UL标签下拉框美化是一款没有使用到select标签,由ul标签和input标签组合,点击下拉项后能获取到值。

    jquery+css实现的ul+li模仿下拉框表单美化效果源码.zip

    jquery+css实现的ul+li模仿下拉框表单美化效果源码.zip

    好看的select下拉框(带搜索功能)javaScript,jquery两种方式实现

    好看的select下拉框(带搜索功能),由于默认select样式过丑而且有些东西还不好改,这个是利用input框和ul来实现一个下拉框的效果。分为不带搜索功能和带搜索功能两个部分。以及jquery与javascript两种实现

    jQuery 自定义下拉框(DropDown)附源码下载

    先给大家展示下效果图,喜欢的朋友可以下载源码哦 效果演示 源码下载 手册网 &lt;ul class=dropdown xss=removed&gt; &lt;li&gt;&lt;a&gt;jQuery特效&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a&gt;网站模板&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/section&gt;

    jQuery实现下拉框多选 jquery-multiselect 的实例代码

    先给大家展示下效果图: 除了jquery,需要引用的样式和js文件: &lt;link rel="stylesheet" type="text/css" href="../assets/jquery.multiselect.css" /&gt; &lt;link rel="stylesheet" type="text/css" href="....

    jQuery模拟selected选择下拉框美化特效

    非常实用的jQuery模拟selected选择下拉框美化特效,对于传统的IE下的下拉框大家可能都觉得 跟现在的页面都格格不入,大家都想美化下,今天推荐的这个JS特效是利用jQuery以及UL改造的 select下拉选择美化特效还是很...

    jquery模拟SELECT下拉框取值效果

    jquery模拟SELECT框,效果图如下: 代码如下: &lt;!DOCTYPE html&gt; &lt;html lang=”en”&gt; &lt;head&gt; &lt;title&gt;jquery模拟SELECT框&lt;/title&gt; &lt;meta charset=”utf-8″&gt; &lt;style&gt; body{...

    jquery.multiselect多选下拉框实现代码

    本文实例为大家分享了jquery.multiselect多选下拉框的实现方法,供大家参考,具体内容如下 第一步:链接下列文件,如果没有,到此网页下载 https://github.com/ehynds/jquery-ui-multiselect-widget,此插件基于...

    jquery仿QQ登录账号选择下拉框效果

    原理就是一个textbox加一个ul模拟下拉框,用font模拟一个下拉按钮。 一、制作静态效果 先用css和html,做出一个应该有的样子。这里这两个我使用的是字体,可以在icomoon网站上面自己制作。用字体的好处是和输入框...

    jquery multiSelect 多选下拉框

    $(“#id”).multiSelect({ oneOrMoreSelected: ‘*’,selectAll:false,noneSelected:’默认显示’ }); Usage: $(‘#id’).multiSelect( options, callback ) Options: selectAll – whether or not to display the ...

    jquery获取自定义属性(attr和prop)实例介绍

    两种都可以,不过新版jquery推荐第二种,两个在其他方面都差不多,我发现的唯一不同就是在checkbox上的时候,需要用prop,不然IE浏览器会不兼容 代码如下:&lt;html xmlns=”http://www.w3.org/1999/xhtml”&gt; &lt...

    JQuery&CSS;&CSS;+DIV实例大全.rar

    推荐jQuery美化select下拉框样式漂亮效果 27.下载jQuery网页表单美化修饰插件(jQtransForm美化表单) 28.一款jquery实现表单输入提示的Autobox插件(基于jquery.ui) 29.一款美化表单下拉列表、复选框等的jquery ...

    Jquery 模拟 select

    非常漂亮的JQuery+ul模拟select下拉框插件

    jQuery制作简洁的多级联动Select下拉框

    今天我们要来分享一款很实用的jQuery插件,它是一个基于jQuery多级联动的省市地区Select下拉框,并且值得一提的是,这款联动下拉框是经过自定义美化过的,外观比浏览器自带的要漂亮许多。另外,这个Select下拉框也...

    jQuery点击页面其他部分隐藏下拉菜单功能

     web页面中,我们一般不用select、option来实现下拉菜单效果,因为下拉框的样式丑且难以美化,所以我们选择控制ul显示隐藏来实现同样且高大上的效果,但是不能像下拉框那样点击页面其他部分,下拉菜单收起或隐藏,...

    下拉框下面生成tree树

    用div+ul模拟出来了select然后用jquery+jquery.easyui.min+json生成下拉树

    jQuery实现下拉菜单动态添加数据点击滑出收起其他功能

    上面的人要hui admin 做页面,本人前端比较菜,这框架也没用...①:请求数据+ul拼接  比较糙,两边icon 无力回天,不过功能是实现了 $.ajax({ url:'/type/reportType', data:{token:getCookie(token)}, type:'post',

Global site tag (gtag.js) - Google Analytics