Specifies that the text box can only enter a jquery code with numbers including decimals

Source: Internet
Author: User

Specifies that the text box can only enter a jquery code with numbers including decimals:
text boxes sometimes specify that only integers can be entered, here is not much to introduce, in particular, see How jquery specifies that a text box can only enter integers section, but sometimes you can enter decimals, and here's an example of how to do this with code examples.
The code example is as follows:

<!DOCTYPE HTML> <HTML> <Head> <MetaCharSet= "Utf-8"> <Metaname= "Author"content= "http://www.softwhy.com/" /> <title>Ant Tribe</title> <Scripttype= "Text/javascript"src= "Mytest/jquery/jquery-1.8.3.js"></Script><Scripttype= "Text/javascript">//The text box can only enter numbers (including decimals) and mask input methods and pasteJQuery.fn.number=function(){   This. Bind ("KeyPress",function(e) {varCode=(E.keycode?E.keycode:e.which); //compatible with Firefox IE    //You can't use the backspace bar under Firefox    if(!$.browser.msie&&(E.keycode==0x8)){return;} if( This. Value.indexof (".")==-1){return(Code>=  - &&Code<=  $)||(Code== $);} Else{returnCode>=  - &&Code<=  $}   });  This. Bind ("Paste",function(){return false;});  This. Bind ("KeyUp",function(){    if( This. Value.slice (0,1) == ".")    {        This. Value= "";   }   });  This. Bind ("Blur",function(){     if( This. Value.slice (-1) == ".")    {        This. Value=  This. Value.slice (0, This. Value.length-1); }   }); }; $(function(){   $("#txt"). Number ();}); </Script></Head><Body><inputtype= "text"ID= "txt" /></Body></HTML>

The above code implements our requirements and allows you to enter numbers in a text box, including integers and decimals.

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=10801

For more information, refer to: http://www.softwhy.com/jquery/

Specifies that the text box can only enter a jquery code with numbers including decimals

Related Article

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.