JQuery防止退格键网页后退的实现代码

时间:2012-03-23    点击:89   
下面是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开发有帮助。
javascript工具库代码
Web开发之JavaScript
CodeMirror2 IE7/IE8 下面未知运行时错误的解决方法
基于jquery完美拖拽,可返回拖动轨迹
获取服务器传来的数据 用JS去空格的正则表达式
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved