问题描述
我的body标签上有一个keydown
事件,它监听end
键(键代码35)和home
按钮(键代码36).
I have a keydown
event on my body tag, and I have it listening for the end
key (keycode 35), and the home
button (keycode 36).
在我的if
块中,我的最后一行是return false;
.但是我的页面仍在滚动!我在if
块中的多个不同位置尝试了return false;
,并尝试使用e.preventDefault();
以及e.bubbles = false;
或代替e.bubbles = false;
.这是我的代码:
In my if
blocks, I have the last line of it as return false;
. Yet my page still scrolls! I've tried the return false;
in multiple different places within my if
block, tried using e.preventDefault();
, as well as or instead of e.bubbles = false;
. This is my code:
$("body").keydown(function(e) {
if(e.ctrlKey && e.keyCode == 83)
{
e.preventDefault();
editForm();
return false;
}
else if(e.which == 35)
{
/* [end] key hit */
console.log("end key hit!");
return false;
}
else if(e.which == 36)
{
/* [home] key hit */
console.log("home key hit!");
return false;
}
});
有人可以帮助我解决这个令人困惑的问题吗?我真的需要它不要在这两个键上滚动.干杯!
Can anyone help me with this confusing issue? I really need it not to scroll on these two keys. Cheers!
编辑 我已经将问题缩小了一点. jScrollPane似乎是一个问题.我将进一步调查并报告.抱歉,麻烦的人.
EDITI have narrowed the problem down a little. It seems to be an issue with jScrollPane. I will investigate further and report back. Sorry for the hassle guys.
推荐答案
好吧,看起来jScrollPane也在使用keyCode 35.转到jScrollPane的未缩小源代码(位于下面的URL)页面,然后搜索35.
Okay, looks like jScrollPane is using keyCode 35 as well. Go to the un-minified source code of jScrollPane (URL below) page and search for 35.
http://jscrollpane.kelvinluck.com/script/jquery.jscrollpane.js
这篇关于页面按结束键滚动并返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!