0
我在我的一个项目中使用了jquery。我有一个场景,我必须将键盘事件添加到表格的td单元格以在其中上下移动。我能够使用以下代码实现此目的。防止页面响应页面滚动的pageup/pagedown事件
这里是我的代码:
<script type="text/javascript">
var tds = jQuery("#myTable td");
tds.bind('keyup', function(event){
var key = event.which;
moveSelection(key, jQuery(this), tds);
event.preventDefault();
});
function moveSelection(key, current_td, all_tds){
var index = parseInt(current_td.attr("id"));
if (key == 13) { //Enter Key
current_td.click();
} else if(key == 38) { //Page Up Key
if(all_tds[index - 1]){
all_tds[index - 1].focus();
}
} else if(key == 40) { //Page Down Key
if(index < all_tds.length){
var next_index = index + 1;
if(next_index < all_tds.length){
all_tds[index + 1].focus();
}
}
}
}
我能够通过TD细胞移动如果页面没有滚动条。但是当页面有滚动条时,当使用PageUp/PageDown键时会发生两件事。
- 我的页面滚动向上/向下基于按下的键。()
- 相应的TD移动选择/向上基于按下的键。
在第一种情况下,可能是因为事件绑定了页面以及我的表tds。我怎样才能防止这一点。当我处理桌子时,我不希望我的页面滚动。我尝试了很多,但失败了。寻找一些帮助。
任何帮助,不胜感激..在此先感谢...
没有解决问题。它的行为与以前一样。 – Venkat 2010-04-15 14:16:00