The
method One or four event combination enables a text box to be entered only with a number
<input type= "text"
onkeypress = ' return/^d$/.test ( String.fromCharCode (Event.keycode)) '
oninput= ' this.value = This.value.replace (/d+/g, "") '
onpropertychange= ' If (!/d+/.test (This.value)) {return;}; This.value=this.value.replace (/d+/g, "") '
onblur = ' This.value = This.value.replace (/d+/g, "") '/>
Methods two, jquery implementation text box can only enter a number
control text box can only enter numbers is a very common requirement, such as phone number input, number of input, etc., this time we need to control the text box can only enter numbers. After using JS control in the state of the English input method to hit the keyboard is not the number of keys to lose, however, when you go to the Chinese input method is entered in Chinese, and then by the space or enter, the Chinese or English letters to enter, this time we need to focus on the text box when the input method is closed, is to not respond to input method switching. The following statement can implement this functionality.
The following statement is written in jquery, and a text box that controls class Checknum can only enter numbers and decimal points.
JS code Collection Code
//Monitor keyboard, only allow input numbers and decimal
$ (". Checknum"). KeyPress ( function (event) {
var keycode = Event.which;
if (keycode = 46 | | (KeyCode >= 48 && keycode <=57)
return true; &NBSP
Else
&NBS P return false; &NBSP
}). focus (function () {
& nbsp this.style.imemode= ' disabled ';
}); &NBSP
IMEMode has four forms, respectively:
active on behalf of input method for Chinese
inactive on behalf of input method for English
Auto representative open Input Method (default)
Disable rep close IME