js 類比select控制項執行個體代碼

來源:互聯網
上載者:User
提示:您可以先修改部分代碼再運行

<!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>類比select控制項</title><style>html,body{height:100%;overflow:hidden;}body,div,form,h2,ul,li{margin:0;padding:0;}ul{list-style-type:none;}body{background:#23384e;font:12px/1.5 5fae8f6f96c59ed1;}#search,#search form,#search .box,#search .select,#search a{background:url(img/search.jpg) no-repeat;}#search,#search .box,#search form{height:34px;}#search{position:relative;width:350px;margin:10px auto;}#search .box{background-position:right 0;}#search form{background-repeat:repeat-x;background-position:0 -34px;margin:0 20px 0 40px;}#search .select{float:left;color:#fff;width:190px;height:22px;cursor:pointer;margin-top:4px;line-height:22px;padding-left:10px;background-position:0 -68px;}#search a{float:left;width:80px;height:24px;color:#333;letter-spacing:4px;line-height:22px;text-align:center;text-decoration:none;background-position:0 -90px;margin:4px 0 0 10px;}#search a:hover{color:#f60;background-position:-80px -90px;}#search .sub{position:absolute;top:26px;left:40px;color:#fff;width:198px;background:#2b2b2b;border:1px solid #fff;display:none;}#search .sub li{height:25px;line-height:24px;cursor:pointer;padding-left:10px;margin-bottom:-1px;border-bottom:1px dotted #fff;}#search .sub li.hover{background:#8b8b8b;}</style><script type="text/javascript">window.onload = function (){var oSelect = document.getElementsByTagName("span")[0];var oSub = document.getElementsByTagName("ul")[0];var aLi = oSub.getElementsByTagName("li");var i = 0;oSelect.onclick = function (event){var style = oSub.style;style.display = style.display == "block" ? "none" : "block";//阻止事件冒泡(event || window.event).cancelBubble = true};for (i = 0; i < aLi.length; i++){//滑鼠划過aLi[i].onmouseover = function (){this.className = "hover"};//滑鼠離開aLi[i].onmouseout = function (){this.className = "";};//滑鼠點擊aLi[i].onclick = function (){oSelect.innerHTML = this.innerHTML}}document.onclick = function (){oSub.style.display = "none";};};</script></head><body><div id="search"> <div class="box"> <form> <span class="select">請選擇遊戲名稱</span> 搜尋 </form> </div> <ul class="sub"> <li>地下城與勇士</li> <li>魔獸世界(國服)</li> <li>魔獸世界(台服)</li> <li>熱血江湖</li> <li>神鬼傳奇</li> <li>大話西遊II</li> <li>QQ幻想世界</li> </ul></div></body></html></td> </tr></table>
提示:您可以先修改部分代碼再運行

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.