When I test the recharge interface, the input amount is retained to three decimal places when the program error, and later thought that the amount of money can only be retained to two digits after the decimal point, the following is the details of my implementation of jquery code, for reference only, the great God do not spray
1$(function() {2 //prevent key input other than the number key3$ ("#zf_money"). KeyDown (function(e) {4Digitinput ($ ( This), e);5 });6$ ("#zf_money"). KeyUp (function() {7 if($( This). val () = = "") {8$ ("#zfz_money"). Text ("0"));9}Else {Ten$ ("#zfz_money"). Text ($ ( This). Val ()); One } A - }); - the functionPrevent (e) { -E.preventdefault?e.preventdefault (): e.returnvalue=false; - }; - + functionDigitinput (el,e) { - vare=e| | window.event;//FF, Chrome IE get event object + varc=e.charcode| | E.keycode;//FF, Chrome ie get keyboard code A varVal=el.val (); at if(c==110| | c==190) {//110 (190)-Point on a small (primary) keyboard -(Val.indexof (".") >=0| |! Val.length) &&prevent (e);//An existing decimal point or text box is empty and the input point is not allowed - -}Else if((c!=8&&c!=46&&//8-backspace, 46-delete -(c<37| | C>40) &&//Notoginseng (max) (max)-left (UP) (right ) Arrow -(c<48| | c>57) &&//48~57-0~9 on the main keyboard in(c<96| | c>105))//96~105-0~9 of the keypad -|| E.shiftkey) {//Shift key, the corresponding code is toPrevent (e);//prevent events from propagating to KeyPress +}Else if(C!=8&&c!=46&&val.indexof (".") >=0) { -(Val.substring (Val.indexof (".") +1). Length) >1&&prevent (e); the}Else if(c!=8&&c!=46&&val.length>5) { * prevent (e); $ }Panax Notoginseng }; -});
A price style is implemented based on the implementation of a text box that can only enter numbers and decimal points (two decimal places are reserved)