The solution of the Chinese input method does not trigger the onkeyup Event

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.