防止在页面中按删除键出现回退效果

function doKey(e) {// 处理键盘事件
    var ev = e || window.event;// 获取event对象
    var obj = ev.target || ev.srcElement;// 获取事件源
    var t = obj.type || obj.getAttribute('type');// 获取事件源类型
    // alert(condition);
    var condition = false;
    if (obj.getAttribute('readonly') == 'readonly'
            || obj.getAttribute('readonly') == true || t == null) {
        condition = (ev.keyCode == 8);
    }
    if (condition || ev.keyCode==220) {
        return false;
    }
}
document.onkeypress = doKey;
document.onkeydown = doKey;
原文地址:https://www.cnblogs.com/njccqx/p/9672523.html