如何使用jquerykeydown函数分别滚动两个列表?
如何使用jquerykeydown函数分别滚动两个列表如何使用jquerykeydown函数分别滚动两个列表?,jquery,Jquery,如何使用jquerykeydown函数分别滚动两个列表 $(document.keydown(function(e1) { // ul list B - insert data if(e.which == leftArrowKey1) { // scroll left }else if(e.which == rightArrowK
$(document.keydown(function(e1)
{
// ul list B - insert data
if(e.which == leftArrowKey1)
{
// scroll left
}else if(e.which == rightArrowKey1 || e.which == spacebarKey1)
// scroll right
}
});
$(document.keydown(function(e2)
{
// ul list B - insert data
if(e2.which == leftArrowKey2)
{
// scroll left
}else if(e2.which == rightArrowKey2 || e2.which == spacebarKey2)
// scroll right
}
});
加载文档后,我可以滚动列表B或A,但不能在同一文档加载中滚动两者。换句话说,如果我首先滚动列表A,我就不能滚动列表B。我只能在点击重新加载按钮后滚动列表B。列表是在
div
s中还是某个父元素中?
如果是这样,只需将键向下
事件放在父元素上,而不是文档上
$('.list').keydown(function(e) { // for each list trap the keydown event
var list = $(this); // store the active list object
if (e.which == leftArrowKey) {
e.PreventDefault();
// scroll the list element left
} else if(e.which == rightArrowKey || e.which == spacebarKey)
e.PreventDefault();
// scroll the list element right
}
});
谢谢TerryR,但这不起作用。只有$(document).keydown似乎有效。为了回答您的问题,我在一个divWow中有一个列表,它没有通过,代码如下