js 防止BACKSPACE键回退的JS方法

function PreventBSK()
{
var bskEventCancel = false;
var _EVENT = window.event;
bskEventCancel = _EVENT && _EVENT.altKey && (_EVENT.keyCode == 8 || _EVENT.keyCode == 37 || _EVENT.keyCode == 39);
if(_EVENT.keyCode == 8)
{
var tagName = _EVENT.srcElement.tagName.toUpperCase();
if(tagName == "TEXTAREA" || tagName == "INPUT")//文本操作不受影响
bskEventCancel = _EVENT.srcElement.readOnly;
else
bskEventCancel = true;
}
_EVENT.cancelBubble = bskEventCancel;
_EVENT.returnValue = !bskEventCancel;
return !bskEventCancel;
}

你可能感兴趣的:(JS&CSS)