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

js教程评论361 views阅读模式

下面是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开发有帮助。

企鹅博客
  • 本文由 发表于 2020年10月1日 07:00:11
  • 转载请务必保留本文链接:https://www.qieseo.com/424106.html

发表评论