仅当未在输入字段中按下该键时才绑定该键(用于使用退格键进行页面转换)?
我不知道为什么,但我已经可以工作了,但今天它停止工作了。基本代码是:
$(document).bind("keydown", function(e){
if (e.keyCode) code = e.keyCode; // für alle Browser
else if (e.which) code = e.which; // für ie
if(code==8) {
$("#outer-frame").fadeOut(400, function (){ //content fade-out
history.back(-1); //gehe einen Schritt in der Browser-History zurück
});
return false; // Browser bricht ab
}
});
而且我还有一个if语句,不再知道它了,它突然停止工作了。 我希望退格键绑定到 keydown 并执行页面转换效果。没问题,只要我想阻止整个事情被调用,如果用户在输入字段中按下退格键,他将被重定向到历史记录中的最后一页。
请帮助我!如果某些东西停止工作,那就太烦人了。
我使用了 css 中的 :focus 选择器,例如 if ( $("input:focus") ...
只是想补充一点,浏览器开关不是我做的,绑定事件和 if(code==8) 是我的编码,淡入淡出和历史也一样,但没有什么独特的,你会发现很多例子,所以我在研究不同的浏览器行为期间做了(我发现了一些类似的代码,但我认为那是 jQuery ...而且 jQuery 很棒!)
。我对 Ken Egozi 和 SimpleCoder 提供的解决方案感到非常满意,并且非常感谢你们俩的帮助!
i don't know why, but i got this already to work but today it stopped working. The base code is:
$(document).bind("keydown", function(e){
if (e.keyCode) code = e.keyCode; // für alle Browser
else if (e.which) code = e.which; // für ie
if(code==8) {
$("#outer-frame").fadeOut(400, function (){ //content fade-out
history.back(-1); //gehe einen Schritt in der Browser-History zurück
});
return false; // Browser bricht ab
}
});
and i also had an if statement, don't know it anymore, it suddenly stopped working.
I want that the backspace key is bind to keydown and execute a page transition effect. No problem as long is i want to prevent the whole thing beeing called if a user hits the backspace key in an input field, es he would be redirected to the last page in his history.
PLS help me! It's so annoying if something just stopped working.
I used the :focus selector from css like if ( $("input:focus") ...
Just want to add that the browser switch is not from me, the bind event and if(code==8) was my coding, fade and history also but nothing unique you'll find a lot of examples so i did during during my research about different browser behaviour (where i found some similiar code, but i think that's jQuery ... and jQuery is awesome!).
I'm so happy with the solutions provided by Ken Egozi and SimpleCoder and really want to thank both of you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果在文本区域、文本框或密码框中按下按键,则需要继续(返回 true)。
添加
到您的处理程序中的
if (code==8)
位之前You need to continue (return true) if he key pressed within a textarea, a textbox or a password box.
Add
to your handler, before the
if (code==8)
bit我会这样做:
另外,正如你所知,jQuery 自动规范化
e.which
属性,因此:可以写为
I would do this:
Also, just so you know, jQuery automatically normalizes the
e.which
property so:can be written as