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
}

/* 选项卡搜索 结束*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值