The Return key when JS disables the read-only text box to get the focus
Source: Internet
Author: User
Sometimes it is inevitable to use a read-only text box. Today, we can find that the read-only text box has a defect. When the focus of the mouse is in the text box, press the backspace to return to the previous page, this problem is a bit annoying. If the user does not know how to enter it, he may lose all the data entered in the text box if he wants to change the content. therefore, you have written a method to store <SCRIPT> </SCRIPT> as needed.
CopyCodeThe Code is as follows: document.doc umentelement. onkeydown = function (EVT ){
VaR B = !! EVT, oevent = EVT | window. event;
If (oevent. keycode = 8 ){
VaR node = B? Oevent.tar get: 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;
}
}
}
}
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