禁用返回键
document.documentElement.onkeydown = function (evt) { //获取事件对象 var elem = event.relatedTarget || event.srcElement || event.target || event.currentTarget; if (event.keyCode == 8) {//判断按键为backSpace键 //获取按键按下时光标做指向的element var elem = event.srcElement || event.currentTarget; //判断是否需要阻止按下键盘的事件默认传递 var name = elem.nodeName; if (name != 'INPUT' && name != 'TEXTAREA') { return _stopIt(event); } var type_e = elem.type.toUpperCase(); if (name == 'INPUT' && (type_e != 'TEXT' && type_e != 'TEXTAREA' && type_e != 'PASSWORD' && type_e != 'FILE')) { return _stopIt(event); } if (name == 'INPUT' && (elem.readOnly == true || elem.disabled == true)) { return _stopIt(event); } } } function _stopIt(e) { if (e.returnValue) { e.returnValue = false; } if (e.preventDefault) { e.preventDefault(); } return false; }