Easyui Numberbox How to enter a specified number of digits, more than the specified number of digits allowed input

Source: Internet
Author: User

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

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.