第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

DOM事件探秘--編程挑戰(zhàn)

標(biāo)簽:
Html/CSS JavaScript

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>下拉菜单</title>
<style type="text/css">

  • {
    margin: 0;
    padding: 0;
    font-size: 13px;
    }
divselect {
width: 186px;
margin: 80px auto;
position: relative;
z-index: 10000;
}

/ 选择框 /

divselect cite {
width: 184px;
height: 24px;
line-height: 24px;
display: block;
color: #807a62;
cursor: pointer;
font-style: normal;
text-indent:1em;
border: 1px solid gray;
background: url(xjt.png) no-repeat right center;
}

/ 选项项样式 /

divselect ul{
display:none;
width: 184px;
border: 1px solid gray;
border-top:none;
}
divselect ul li{
cursor: pointer;
list-style:none;
text-indent:1em;
height: 24px;
line-height: 24px;
}

</style>

<script type="text/javascript">
window.onload = function () {
var oCite = document.getElementsByTagName('cite')[0];
var oUl = document.getElementsByTagName('ul')[0];
var oLis = oUl.getElementsByTagName('li');
var litxt = null;
var x = -1;
var y = null;
/ cite点击效果 /
oCite.onclick = cliFun;
function cliFun(e) {
e = event || window.event;
/取消事件冒泡/
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
oUl.style.display = 'block';
}

/*  点击页面空白地方,选择框消失  */
document.onclick = function () {
    oUl.style.display = 'none';
    litxt = null;
}

/*  鼠标浮动在每个选择项上面时,背景颜色改变    */
for (var i = 0, l = oLis.length; i < l; i++) {
    oLis[i].onmouseover = function () {
        this.style.background = 'silver';
    }
    oLis[i].onmouseout = function () {
            this.style.background = '#fff';
        }
        // 点击选择项时,改变cite的内容
    oLis[i].onclick = function () {
        oCite.innerHTML = this.innerHTML;
    }
}

/*  键盘事件    */
document.onkeydown = function (e) {
    e = event || window.event;

    //  y用来记录上一次键盘的选项索引
    y = x;
    /*取消事件冒泡*/
    if (e.stopPropagation) {
        e.stopPropagation();
    } else {
        e.cancelBubble = true;
    }
    //按下向下键
    if (e.keyCode == 40) {
        oUl.style.display = 'block';
        x = x + 1;
        if (x > oLis.length-1) {
            x = 0;
        }
        oLis[x].style.background = 'silver';
        oLis[y].style.background = '#fff';
        litxt = oLis[x].innerHTML;
    }

    //按下向上键
    if (e.keyCode == 38) {
        oUl.style.display = 'block';
        x = x - 1;
        if (x < 0) {
            x = oLis.length-1;
        }
        oLis[x].style.background = 'silver';
        oLis[y].style.background = '#fff';
        litxt = oLis[x].innerHTML;          
    }

    //按下回车键
    if (e.keyCode == 13) {
        oCite.innerHTML = litxt;
        oUl.style.display = 'none';
    }

    //按下esc键盘
    if (e.keyCode == 27) {
        oUl.style.display = 'none';
        x=-1;
    }

}

}

</script>
</head>
<body>
<div id="divselect">
<cite>请选择分类</cite>
<ul>
<li>ASP开发</li>
<li>.NET开发</li>
<li>PHP开发</li>
<li>Javascript开发</li>
<li>Java特效</li>
</ul>
</div>
</body>
</html>

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消