JAVAscript——菜單下拉式清單練習

來源:互聯網
上載者: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>無標題文檔</title><style type="text/css">#a{    width:80px;    height:30px;    background-color:#CFF;    text-align:center;    line-height:30px;    vertical-align:middle;}#b{    width:80px;    height:180px;    background-color:#CF9;    text-align:center;    line-height:30px;    vertical-align:middle;}#b div{    text-align:center;    line-height:30px;    vertical-align:middle;}</style></head><body><div id="q" onclick="wai()"><input id="a" value="菜單" onclick="caidan()" onmouseout="likai()"/>    <div id="b" style="display:none" >        <div id="c" onmouseover="over(this)" onmouseout="out(this)" onclick="dianji(this)">蘋果</div>        <div id="d" onmouseover="over(this)" onmouseout="out(this)" onclick="dianji(this)">梨子</div>        <div id="e" onmouseover="over(this)" onmouseout="out(this)" onclick="dianji(this)">山竹</div>        <div id="f" onmouseover="over(this)" onmouseout="out(this)" onclick="dianji(this)">桃子</div>        <div id="g" onmouseover="over(this)" onmouseout="out(this)" onclick="dianji(this)">核桃</div>        <div id="h" onmouseover="over(this)" onmouseout="out(this)" onclick="dianji(this)">香蕉</div>    </div></div></body><script type="text/javascript">function caidan(b){    document.getElementById("b").style.display="block";        stopEventBubble(event); //阻止事件冒泡}function over(t){    t.style.backgroundColor="gray";    }function out(y){    y.style.backgroundColor="#CF9";    }function dianji(m){    var n=document.getElementById("a");    n.value = m.innerText;}function stopEventBubble(event){        var e=event || window.event;        if (e && e.stopPropagation)        {            e.stopPropagation();            }        else        {            e.cancelBubble=true;        }    }//隱藏function wai(){    document.getElementById("b").style.display="none";    }</script></html>

 

JAVAscript——菜單下拉式清單練習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.