Home > Web Front-end > JS Tutorial > body text

Javascript prohibits backspace key (Backspace) example code_javascript skills

WBOY
Release: 2016-05-16 17:14:57
Original
912 people have browsed it
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;

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!