Because most customers are not computer-literate big rookie. So the wrong operation is more, sometimes do not select the text box, and then accidentally pressed the backspace, just hard to fill out the form on the back of nothing. Search the Internet a lot of information, and then integrated a bit. Share to everyone. I also hope that the yogurt sister to see my first technical blog. Oh, don't mind me mentioning you. )。 Don't say much nonsense. On the source.
Copy Code code as follows:
$ (function () {
Handle keyboard events No 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
Get the event type as a criterion
var vreadonly = Obj.getattribute (' readonly ');
var venabled = Obj.getattribute (' enabled ');
Handling Null value conditions
Vreadonly = (vreadonly = null)? False:true;
venabled = (venabled = null)? true:venabled;
When you hit the BACKSPACE key, the event source type is a password or a single line, multi-line text,
And the ReadOnly property is True or the Enabled property is False, the BACKSPACE key is invalidated
var flag1= (Ev.keycode = = 8 && (t== "Password" | | t== "TEXT" | | t== "TEXTAREA")
&& (vreadonly | | venabled!=true)) True:false;
When the BACKSPACE key is hit, the event source type is not a password or a single line or multi-line text, the BACKSPACE key is invalidated
var flag2= (Ev.keycode = = 8 && t!= "password" && t!= "text" && t!= "textarea")
? true:false;
Judge
if (Flag2) {
return false;
}
if (FLAG1) {
return false;
}
}
No back key for Firefox, Opera
Document.onkeypress=banbackspace;
No back key acts on IE, Chrome
Document.onkeydown=banbackspace;
Window.history.forward (1)//Screen browser with the back key
})
the areas to be noted are:
This piece of code must be placed in the initialization method. Then use Document.onkeypress=banbackspace to call your own method of writing.
Copy Code code as follows:
Vreadonly = (vreadonly = null)? False:true for this code, the original colon is followed by the Vreadonly<span style= "font-family:arial, Helvetica, Sans-serif;" The value of > was later found to be null in my project, not null and changed to TRUE. </span>
The above method enables you to block the browser back event by pressing the backspace when Text,password,textare, but does not block the backspace event when the text box has a value. This is my first blog, I hope you have a lot to join in.