JS disables the BACKSPACE key when the read-only text box gets focus

Source: Internet
Author: User


Document.documentElement.onkeydown = function (evt) {
var b =!! EVT, oevent = evt | | window.event;
if (Oevent.keycode = = 8) {
var node = b? OEvent.target:oEvent.srcElement;
var reg =/^ (Input|textarea) $/i, Regtype =/^ (Text|textarea) $/i;
if (!reg.test (node.nodename) | | |!regtype.test (node.type) | | node.readonly | | node.disabled) {
if (b)
{
Oevent.stoppropagation ();
}
Else
{
Oevent.cancelbubble = true;
Oevent.keycode = 0;
Oevent.returnvalue = false;
}
}
}
}

Sometimes it's hard to use a read-only box, can be found today, read-only text box has a flaw, when the mouse focus in the text box when the Back button (BackSpace), will be back to the previous page, the problem is a bit annoying, the user is not clear can input, If he sees a text box that wants to change something in it, click on it, and it's possible that all the data you've filled out will be lost. So I wrote a way for everyone to put in <script></script> when they need it;

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.