Reference:
Http://www.cnblogs.com/xcsn/p/3413074.html
Http://www.soso.io/article/21182.html
Recently do an input box can only enter a decimal point two decimal places, when listening to the KeyUp event, when the input method to Chinese, and then press ENTER, so still can enter other characters (Firefox does not have this problem, Google has this problem), then Baidu only know the reason, the specific reference above two URLs.
Before you change the wording:
<inputtype= "text"name= "Inputorp_i"ID= "Inputorp_i"AutoComplete= "Off" onkeyup= "clearnonum(this)"/> <spanID= "inputorp_s"></span> <Script>//only numbers and decimal points can be entered functionClearnonum (obj) {//first replace the non-digital, except the number and.Obj.value=Obj.value.replace (/[^\d.]/G,""); //the first one must be guaranteed to be a number instead of.Obj.value=Obj.value.replace (/^\./G,""); //guarantee that only one appears. And not more.Obj.value=Obj.value.replace (/\. {2,}/G,"."); //guaranteed. Appears only once, and cannot occur more than two timesObj.value=Obj.value.replace (".","$#$"). Replace (/\./G,""). Replace ("$#$","."); Obj.value=Obj.value.replace (/^ (\-) * (\d+) \. (\d\d). *$/, '$1$2.$3'); //only two decimal places can be entered } </Script>
The modified wording:
<inputtype= "text"name= "Inputorp_i"ID= "Inputorp_i"AutoComplete= "Off"/> <spanID= "inputorp_s"></span> <Script> //First judge the browser is not the evil of IE, no way, write things also have IE users varBind_name= 'input'; if(Navigator.userAgent.indexOf ("MSIE") != -1) {Bind_name= 'PropertyChange'; } $ ('#inputorp_i'). Bind (Bind_name,function() {Clearnonum ( This); }) //only numbers and decimal points can be entered functionClearnonum (obj) {//first replace the non-digital, except the number and.Obj.value=Obj.value.replace (/[^\d.]/G,""); //the first one must be guaranteed to be a number instead of.Obj.value=Obj.value.replace (/^\./G,""); //guarantee that only one appears. And not more.Obj.value=Obj.value.replace (/\. {2,}/G,"."); //guaranteed. Appears only once, and cannot occur more than two timesObj.value=Obj.value.replace (".","$#$"). Replace (/\./G,""). Replace ("$#$","."); Obj.value=Obj.value.replace (/^ (\-) * (\d+) \. (\d\d). *$/, '$1$2.$3'); //only two decimal places can be entered } </Script>
The solution of the Chinese input method does not trigger the onkeyup Event