【发布时间】:2017-01-02 19:56:59
【问题描述】:
我使用的是 jQuery 1.12。当有人将鼠标悬停在 LI 元素上时,我有这个类
.select-options li:hover {
color: gray;
background: #fff;
}
如何使用 jQuery 触发将此类应用于 LI 元素?这个我试过了
$(".select").bind('keydown', function(event) {
elt = $(this).find('.select-options li:hover')
if (elt.length == 0) {
elt = $(this).find('.select-options li:first')
} // if
var next;
switch(event.keyCode){
// case up
case 38:
break;
case 40:
next = $(elt).next();
console.log($(next).text());
$(next).trigger('mouseenter');
break;
}
});
但是 $(next).trigger('mouseenter');似乎没有工作。你可以在这里查看我的小提琴——http://jsfiddle.net/cwzjL2uw/15/。单击“选择状态”下拉菜单,然后单击键盘上的向下键以触发上面的代码块。
【问题讨论】:
标签: jquery css hover mouseenter