Common methods for limiting input 1. To cancel the dotted box when the button is pressed, add the attribute value hideFocus or HideFocus=true in the input Copy code The code is as follows:<input type="submit" value="Submit" hidefocus="true" /> 2. To read only the text box content, add the attribute value readonly in input Copy code The code is as follows:<input type="text" readonly /> 3. Prevent the TEXT document from being cleared after going back (the style content can be used as a class reference) Copy code The code is as follows:<input type="text" style="behavior:url(#default#savehistory);" /> 4. The ENTER key moves the cursor to the next input box Copy code The code is as follows:<input type="text" onkeydown="if(event.keyCode==13)event.keyCode=9" /> 5. Only Chinese (flashing) Copy code The code is as follows:<input type="text" onkeyup="value=value.replace(/[ -~]/g,'')" onkeydown="if(event.keyCode==13)event.keyCode=9" /> 6. Only numbers (flashing) Copy code The code is as follows:<input type="text" onkeyup="value=value.replace(/[^\d]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" /> 7. Only numbers (no flashing) Copy code The code is as follows:<input type="text" style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9" onkeypress="if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false" /> 8. Only English and numbers can be entered (with flashing) Copy code The code is as follows:<input type="text" onkeyup="value=value.replace(/[\W]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" /> 9. Block input method Copy code The code is as follows:<input type="text" name="url" style="ime-mode: disabled" onkeydown="if(event.keyCode==13)event.keyCode=9" /> 10. Only numbers, decimal points, and minus signs (-) can be entered (no flashing) Copy code The code is as follows:<input onkeypress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false" /> 11. Only two decimal places or three decimal places can be entered (flashing) Copy code The code is as follows:<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}" /> |
<<: The principle and configuration of Nginx load balancing and dynamic and static separation
>>: Facebook's nearly perfect redesign of all Internet services
1. Introduction I have been studying the principl...
This article describes various ways to implement ...
background Indexes are a double-edged sword. Whil...
There are also two servers: Preparation: Set the ...
Table of contents status quo Solution Further sol...
<br />The most common mistake made by many w...
We often encounter this situation in front-end de...
This article shares the specific code of vue3 enc...
How to solve the timeout problem when pip is used...
At first I thought it was a speed issue, so I late...
This article shares the installation tutorial of ...
Prerequisites A cloud server (centOS of Alibaba C...
Preface At work, we often need to operate in a Li...
Table of contents Rendering API changes Render fu...
There are many loop statements in JavaScript, inc...