<div id="divselect"> <cite>请选择分类</cite> <ul> <li id="li"><a href="javascript:;" selectid="1">ASP开发</a></li> <li><a href="javascript:;" selectid="2">.NET开发</a></li> <li><a href="javascript:;" selectid="3">PHP开发</a></li> <li><a href="javascript:;" selectid="4">Javascript开发</a></li> <li><a href="javascript:;" selectid="5">Java特效</a></li> </ul> </div> var box = document.getElementById('divselect'), title = box.getElementsByTagName('cite')[0], menu = box.getElementsByTagName('ul')[0], as = box.getElementsByTagName('a'), index = -1; // 点击三角时 title.onclick = function(event) { // 执行脚本 event = event || window.event; menu.style.display = 'block'; if (event && event.stopPropagation) { event.stopPropagation(); }else { event.cancelBuble = true; } document.onkeyup = function (event) { console.log(event.keyCode); event = event || window.event; for (var i = 0; i < as.length; i++) { as[i].style.backgroundColor = "#fff"; } if (event.keyCode==38) { index--; as[index].style.backgroundColor = "#eee"; if (index<0) { index = as.length; } }else if (event.keyCode==40) { index++; as[index].style.backgroundColor = "#eee"; if (index>as.length) { index = 0; } } } }
if (index<0) {index = as.length;}和if (index>as.length) {index = 0;}都没有被执行,为什么?
Kusoku