You can only enter numbers in the control text box. For example, you can enter phone numbers and numbers. In this case, you must only enter numbers in the control text box. After JavaScript control is used, you cannot enter non-numeric keys on the keyboard in the English input method state. However, when you switch to the Chinese Input Method, you enter Chinese characters, press the space or enter key, and enter the Chinese or English letters. In this case, we need to disable the input method when getting the focus in the text box, that is, it does not respond to the switch of the input method. The following statement can implement this function.
The following statement is written using jquery. Only numbers and decimal places can be entered in the text box that controls the class as checknum.
JS Code
- // Listen to the keyboard. Only numbers and decimal places are allowed.
- $ (". Checknum"). keypress (function (event ){
- VaR keycode = event. Which;
- If (keycode = 46 | (keycode> = 48 & keycode <= 57 ))
- Return true;
- Else
- Return false;
- }). Focus (function (){
- This. style. imemode = 'Disabled ';
- });
// Listen to the keyboard. Only numbers and decimal places can be entered $ (". checknum "). keypress (function (event) {var keycode = event. which; If (keycode = 46 | (keycode >=48 & keycode <= 57) return true; elsereturn false ;}). focus (function () {This. style. imemode = 'Disabled ';});
Imemode has four forms:
Active indicates that the input method is Chinese.
Inactive indicates that the input method is in English.
Auto indicates that the input method is enabled (default)
Disable indicates that the input method is disabled.
Post original turn: http://haohaoxuexi.iteye.com/blog/1137834