我是靠谱客的博主 无心白猫,这篇文章主要介绍JQuery防止退格键网页后退的实现代码,现在分享给大家,希望可以做个参考。

下面是Js片段在IE9,Firebox 10.0.2 中测试过 :

复制代码 代码如下:

$(document).keydown(function (e) {
var doPrevent;
if (e.keyCode == 8) {
var d = e.srcElement || e.target;
if (d.tagName.toUpperCase() == 'INPUT' || d.tagName.toUpperCase() == 'TEXTAREA') {
doPrevent = d.readOnly || d.disabled;
}
else
doPrevent = true;
}
else
doPrevent = false;

if (doPrevent)
e.preventDefault();
});

关于如何确定Backspace键的代码可以通过这里. 
 希望对您Web开发有帮助。

最后

以上就是无心白猫最近收集整理的关于JQuery防止退格键网页后退的实现代码的全部内容,更多相关JQuery防止退格键网页后退内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(120)

评论列表共有 0 条评论

立即
投稿
返回
顶部