Home  >  Article  >  Web Front-end  >  Javascript prohibits backspace key (Backspace) example code_javascript skills

Javascript prohibits backspace key (Backspace) example code_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:14:57904browse
Copy code The code is as follows:

function banBackSpace(e) {
var ev = e || window.event; //Get the event object
var obj = ev.target || ev.srcElement;//Get the event source
var t = obj.type || obj.getAttribute('type');/ /Get the event source type
//Get the event type used as the judgment condition var vReadOnly = obj.readOnly;
var vDisabled = obj.disabled;
                                                                                                              vReadOnly = (vReadOnly == undefined) ? false : vReadOnly;
vDisabled = (vDisabled == undefined) ? true : vDisabled;
//When the Backspace key is pressed, the event source type is password or single or multi-line text " text" || t == "textarea") && (vReadOnly == true || vDisabled == true);
                           //When the Backspace key is pressed, the event source type is not a password or a single line or multi-line text, then The backspace key is invalid
var flag2 = ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea";
                                 (flag2 || flag1) return false

                                                                                                                                                       
document.onkeydown = banBackSpace;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn