//Handle keyboard event disable back key (Backspace) password or single line, multiline text box except
function Banbackspace (e) {
var ev = e | | window.event;//get Event Object
var obj = Ev.target | | ev.srcelement;//get Event Source
var t = Obj.type | | obj.getattribute (' type ');//Get Event Source Type
//Gets the type of event that is used as the judging condition
var vreadonly = Obj.getattribute (' readonly ');
var venabled = Obj.getattribute (' enabled ');
//Handling Null values case
vreadonly = (vreadonly = = null)? false:vreadonly;
venabled = (venabled = = null)? true:venabled;
//When the BACKSPACE key is hit, the event source type is password or single line, multiline text,
///And the ReadOnly property is True or the Enabled property is False, the BACKSPACE key fails
var Flag1 = (Ev.keycode = = = 8 && (t = = "password" | | t = "text" | | t = "TEXTAREA")
&& (vreadonly = = True | | venabled! = TRUE))? True:false;
//When the BACKSPACE key is hit, the event source type is non-password or single-line, multiline text, the BACKSPACE key fails
var Flag2 = (Ev.keycode = = 8 && t! = "password" && t! = "text" && t! = "textarea")? True: false;
//Judgment
if (flag2) {
return false;
}
if (Flag1) {
return false;
}
}
//Disable Back button action on Firefox, Opera
document.onkeypress = banbackspace;
//Disable back key action on IE, Chrome
document.onkeydown = banbackspace;
JS prevents backspace from returning to the previous interface (compatible with various browsers)