Handling keyboard events prevents back key (Backspace) passwords or single-line, multiline text boxes except

Source: Internet
Author: User

<script type= "Text/javascript" >
Handling keyboard events prevents back key (Backspace) passwords or single-line, multiline text boxes except
function Forbidbackspace (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 event type as a criterion
var vreadonly = obj.readonly;
var vdisabled = obj.disabled;
Handling Undefined value Cases
Vreadonly = (Vreadonly = = undefined)? False:vreadonly;
vdisabled = (vdisabled = = undefined)? true:vdisabled;
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 disabled property is true, the BACKSPACE key fails
var Flag1 = Ev.keycode = = 8 && (t = = "password" | | t = = "text" | | t = = "textarea") && (Vreadonly = True | | vdisabled = = true);
When the BACKSPACE key is hit, the event source type is non-password or single-line, multiline text, the BACKSPACE key is invalidated
var Flag2 = Ev.keycode = = 8 && t! = "password" && t! = "text" && t! = "TEXTAREA";
Judge
if (Flag2 | | flag1) return FALSE;
}
Disable Back button action on Firefox, Opera
document.onkeypress = Forbidbackspace;
Disable back key action on IE, Chrome
Document.onkeydown = Forbidbackspace;
</script>

Handling keyboard events prevents back key (Backspace) passwords or single-line, multiline text boxes except

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.