Search on the Internet a lot of code, found that the general use of Replace or window.event.returnValue, do not know that I use the wrong way, or code where the wrong place, the total feeling is not good, The filter that comes with Numberbox is found to be very useful when the input is forbidden.
Please look at the code:
Function: The display can only be two decimal places, when the input if there are already two decimal places, then prohibit the input
JSP code: <input name= "Object.fixrate" class= "Easyui-numberbox _fixrate" onkeyup= " Setfixrate (this,event) " data-options=" Required: true,precision:2 " style = "width:30px;text-align: right;" /> js Code: Function setfixrate (tt,event) {//var value = $ ('. _fixRate '). Numberbox (' GetValue ');//cannot use Numberbox's GetValue, this is the value of the hidden box//If there are decimal points var value = $ ('. _fixrate '). Val ();// This is the value of the input box if (Value.indexof (".") >= 0) {//If the decimal point is included if (Value.substring (Value.indexof (".") +1). Length) >=2) {//If the number of decimal digits already has two bits//window.event.returnvalue = false;//$ ('. _fixrate '). Val ( Value.replace (/^ (\-) * (\d+) \. ( \d\d). *$/, ' $1$2.$3 ');//$ ('. _fixrate '). Numberbox (' filter ', false); $ ('. _fixrate '). Numberbox (' Options '). Filter = function () { //Let filter return false disables keystrokes input return false;};} else{ //Remember to write else, otherwise the nunberbox will not be allowed to enter the $ again ('. _fiXrate '). Numberbox (' Options '). Filter = function () { return true;}}}
Easyui Numberbox How to enter a specified number of digits, more than the specified number of digits allowed input