Copy codeThe Code is as follows:
Function banBackSpace (e ){
Var ev = e | window. event; // obtain the event object
Var obj = ev.tar get | ev. srcElement; // obtain the event Source
Var t = obj. type | obj. getAttribute ('type'); // obtain the event source type.
// Obtain the event type used as the judgment Condition
Var vReadOnly = obj. readOnly;
Var vDisabled = obj. disabled;
// Process the undefined Value
VReadOnly = (vReadOnly = undefined )? False: vReadOnly;
VDisabled = (vDisabled = undefined )? True: vDisabled;
// When you press the Backspace key, the event source type is password or single-line or multi-line text,
// If the readOnly attribute is true or the disabled attribute is true, the Return key is invalid.
Var flag1 = ev. keyCode = 8 & (t = "password" | t = "text" | t = "textarea ") & (vReadOnly = true | vDisabled = true );
// When you press the Backspace key, the Backspace key is invalid if the event source type is non-Password, single-line, or multi-line text.
Var flag2 = ev. keyCode = 8 & t! = "Password" & t! = "Text" & t! = "Textarea ";
// Judge
If (flag2 | flag1) return false
}
// Disable the backspace key for Firefox and Opera
Document. onkeypress = banBackSpace;
// Disable the backspace key for IE and Chrome
Document. onkeydown = banBackSpace;