SoFunction
Updated on 2025-02-28

JavaScript implements the restrictive usage of input input box

1. Cancel the dotted box when the button is pressed
Add attribute value hideFocus or HideFocus=true

2. Read-only text box content
Add attribute value in input readonly

3. Prevent TEXT documents from being cleared back and forth (the style content can be used as a class reference)
<INPUT style=behavior:url(#default#savehistory); type=text id=oPersistInput> 




The key can move the cursor to the next input box.
<input onkeydown="if(==13)=9" > 

5. Only in Chinese (with flashing)
<input onkeyup="value=(/[ -~]/g,'')" onkeydown="if(==13)=9"> 

6. Only numbers (with flashes)
<input onkeyup="value=(/[^\d]/g,'') "onbeforepaste="('text',('text').replace(/[^\d]/g,''))"> 

7. Only numbers (no flashing)
<input style="ime-mode:disabled" onkeydown="if(==13)=9" onKeyPress="if ((<48 || >57)) =false"> 

8. Only enter English and numbers (with flashes)
<input onkeyup="value=(/[\W]/g,'')" onbeforepaste="('text',('text').replace(/[^\d]/g,''))"> 

9. Blocking input method
<input type="text" name="url" style="ime-mode:disabled" onkeydown="if(==13)=9"> 

10. Only enter numbers, decimal points, minus signs (-) characters (no flashing)
<input onKeyPress="if (!=46 && !=45 && (<48 || >57)) =false"> 

11. Only two decimal places and three decimal places (with flashing)
<input maxlength=9 onkeyup="if((/^\d{3}$/))value=(value,parseInt(value/10)) ;value=(/\.\d*\./g,'.')" onKeyPress="if((<48 || >57) && !=46 && !=45 || (/^\d{3}$/) || /\.\d{3}$/.test(value)) {=false}" id=text_kfxe name=text_kfxe> 


------------------------------------------------------------------------
<input type="text" name="input1" value="China">

How to make the content in the input read-only, that is, the user does not change the content.
<input type="text" name="input1" value="China" onfocus=()>
<input type="text" name="input1" value="China" readonly>
<input type="text" name="input1" value="China" disabled>
It is best not to use disabled, otherwise the value inside will not be able to be removed.
<input type="text" name="input1" value="China" readonly="true">
<input type="text" name="input1" value="China" readonly style="color:#999;">