Js Code that is commonly used to restrict input
1. when the cancel button is pressed, add the value hideFocus or HideFocus = true <input type = "submit" value = "submit" hidefocus = "true"/> 2 to the input box. read-only text box content, add the attribute value readonly in input <input type = "text" readonly/> 3. prevent TEXT files from being cleared (style content can be referenced as a class) <input type = "text" style = "behavior: url (# default # savehistory ); "/> 4. the ENTER key allows the cursor to move to the next input box <input type = "text" onkeydown = "if (event. keyCode = 13) event. keyCode = 9 "/> 5. only Chinese (with flashing) <input type = "text" onkeyup = "Value = value. replace (/[-~] /G, '')" onkeydown = "if (event. keyCode = 13) event. keyCode = 9 "/> 6. only numbers (with flashing) <input type = "text" onkeyup = "value = value. replace (/[^ \ d]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g, '')"/> 7. it can only be a number (no flashing) <input type = "text" style = "ime-mode: disabled" onkeydown = "if (event. keyCode = 13) event. keyCode = 9 "onkeypress =" if (event. keyCode <48 | event. keyCode> 57) ev Ent. returnValue = false "/> 8. only English and numbers (with flashing) can be entered. <input type = "text" onkeyup = "value = value. replace (/[\ W]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g, '')"/> 9. blocked input Method <input type = "text" name = "url" style = "ime-mode: disabled" onkeydown = "if (event. keyCode = 13) event. keyCode = 9 "/> 10. only numbers, decimal points, minus (-) characters (no flashing) <input onkeypress = "if (event. keyCode! = 46 & event. keyCode! = 45 & (event. keyCode <48 | event. keyCode> 57) event. returnValue = false "/> 11. only two decimal places can be entered, and three decimal places (with flashing) <input type = "text" maxlength = "9" onkeyup = "if (value. match (/^ \ d {3} $/) value = value. replace (value, parseInt (value/10); value = value. replace (/\. \ d *\. /g ,'. ') "onkeypress =" if (event. keyCode <48 | event. keyCode> 57) & event. keyCode! = 46 & event. keyCode! = 45 | value. match (/^ \ d {3 }$/) | /\. \ d {3} $ /. test (value) {event. returnValue = false} "/>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]