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.
Copy codeThe 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;
}
}
}
}