posts - 20,  comments - 2,  trackbacks - 0

作者: tianshi0253  链接:http://tianshi0253.javaeye.com/blog/204995  发表时间: 2008年06月18日

声明:本文系JavaEye网站发布的原创博客文章,未经作者书面许可,严禁任何网站转载本文,否则必将追究法律责任!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <title>my select</title>
  <style type="text/css">
  <!--
    body
    {
      margin: 0px;
      padding: 30px 0px 0px 30px;
      background-color: #CFDFEF;
      font-size: 12px;
    }
    .selectA
    {
      width: 92px;
      height: 17px;
      padding-left: 10px;
      padding-top: 5px;
      background-image: url(http://labs.utombox.com/select2css/tm2008-select.gif);
      overflow: hidden;
      cursor: pointer;
    }
    .selectB
    {
      display: none;
      width: 81px;
      height: auto;
      background-image: url(http://labs.utombox.com/select2css/tm2008-select.gif);
      background-position: -102px 0px;
      border-bottom: 1px solid #4EA0D1;
    }
    .selectB .item
    {
      width: 71px;
      height: 17px;
      background-image: url(http://labs.utombox.com/select2css/tm2008-select.gif);
      background-position: -102px 0px;
      padding-left: 10px;
      padding-top: 5px;
      overflow: hidden;
      cursor: pointer;
    }
  -->
  </style>
  <script type="text/javascript">
  <!--
    //val
    var items = null;
    var selectA = null;
    var selectB = null;
    var selectAClicked = false;

    //method
    function $(s)
    {
      return document.getElementById(s);
    }

    window.onload = function()
    {
      items = [$("itemA"),$("itemB"),$("itemC"),$("itemD"),$("itemE"),$("itemF"),$("itemG"),$("itemH")];
      selectA = $("selectA");
      selectB = $("selectB");
      //init
      items[0].style.backgroundPosition = "0px -66px";
      //selectA event
      selectA.onmouseover = function()
      {
        if(selectAClicked)
          return;
        this.style.backgroundPosition = "0px -22px";
      }
      selectA.onmouseout = function()
      {
        if(selectAClicked)
          return;
        this.style.backgroundPosition = "0px 0px";
      }
      selectA.onclick = function()
      {
        if(selectAClicked)
        {
          selectAClicked = false;
          this.style.backgroundPosition = "0px -22px";
          selectB.style.display = "none";
          return;
        }
        selectAClicked = true;
        this.style.backgroundPosition = "0px -44px";
        selectB.style.display = "block";
      }
      //selectB event
      //none
      //items event
      function itemMouseOver()
      {
        this.style.backgroundPosition = "0px -88px";
      }
      function itemMouseOut()
      {
        if(this.innerHTML == selectA.innerHTML)
        {
          this.style.backgroundPosition = "0px -66px";
          return;
        }
        this.style.backgroundPosition = "-102px 0px";
      }
      function itemClick()
      {
        for(var i=0,length=items.length;i<length;i++)
          items[i].style.backgroundPosition = "-102px 0px";
        this.style.backgroundPosition = "0px -66px";
        selectA.innerHTML = this.innerHTML;
        selectB.style.display = "none";
        selectA.style.backgroundPosition = "0px 0px";
        selectAClicked = false;
      }
      for(var i=0,length=items.length;i<length;i++)
      {
        items[i].onmouseover = itemMouseOver;
        items[i].onmouseout = itemMouseOut;
        items[i].onclick = itemClick;
      }
    }
  //-->
  </script>
</head>

<body>

<div class="selectA" id="selectA">itemA</div>
<div class="selectB" id="selectB">
  <div class="item" id="itemA">itemA</div>
  <div class="item" id="itemB">itemB</div>
  <div class="item" id="itemC">itemC</div>
  <div class="item" id="itemD">itemD</div>
  <div class="item" id="itemE">itemE</div>
  <div class="item" id="itemF">itemF</div>
  <div class="item" id="itemG">itemG</div>
  <div class="item" id="itemH">itemH</div>
</div>

</body>
</html>

 


本文的讨论也很精彩,浏览讨论>>


JavaEye推荐




文章来源:http://tianshi0253.javaeye.com/blog/204995
posted on 2008-06-18 09:09 姚文超 阅读(87) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: