<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sealyu

    --- 博客已遷移至: http://www.sealyu.com/blog

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks

    Few days back, my friend Parleen asked me how can we make a textbox which just accepts only numbers specially digits only. And, for his I come up with this solution of textbox which only accepts digits, and if you try to enter any alpha bates in it then it displays the error message with animation.

    View Demo

    HTML Code

    <input type="text"name="quantity"id="quantity"/><span id="errmsg"></span>

    As you can see above, I’ve given the name and id of textbox to “quantity” in this example.This is the textbox which only accepts numbers (digits only). You can see “span” after textbox which is used to display the error message with fading effect using jQuery.

    Javascript Code

    First of all, we need to use jQuery library as we’re using the jquery’s function to accept only digits.

    <script type="text/javascript"src="jquery.js"></script>

    Now le’ts write the code in JavaScript using jQuery to accept only digits in textbox and displaying error with animation.

    //when key is pressed in the textbox$("#quantity").keypress(function (e)

    {

      //if the letter is not digit then display error and don't type anything

      if( e.which!=8&& e.which!=0&&(e.which<48|| e.which>57))

      {

        //display error message

        $("#errmsg").html("Digits Only").show().fadeOut("slow");

        returnfalse;

      }

    });

    When the key is pressed, we’re using the key’s ASCII value to check which button is pressed. In first expression, delete, tab or backspace button is is checked and “8″ is the ASCII values of the Back-space. Digits are checked in the second expression. “48″ is the ASCII values of “0″ and “57″ is the ASCII values of “9″. The the ASCII values of the other digits lies between “48″ to “57″. And, if the key pressed values doesn’t lies withing these range, then we are displaying the error message with jQuery’s fading effect.

    And, the “return false” statement means that this functions returns false values which means not to type anything on the text box.

    Download Full Source Code

    posted on 2009-11-06 17:46 seal 閱讀(386) 評論(0)  編輯  收藏 所屬分類: JQuery
    主站蜘蛛池模板: 四虎影视在线永久免费看黄| 亚洲精品一品区二品区三品区| 无码国产精品一区二区免费vr| 永久免费av无码网站大全| 免费无码国产V片在线观看| 久久国产精品亚洲综合 | 性xxxx视频播放免费| 婷婷久久久亚洲欧洲日产国码AV| 黄页网站在线看免费| 亚洲麻豆精品果冻传媒| 波多野结衣久久高清免费| 91福利免费网站在线观看| 亚洲国模精品一区| 欧洲人成在线免费| 国产成人综合亚洲| 久久久久亚洲av无码专区导航| 色欲国产麻豆一精品一AV一免费| 亚洲高清国产拍精品熟女| 99精品国产免费久久久久久下载| 国产精品玖玖美女张开腿让男人桶爽免费看| 亚洲精品高清国产一久久| 亚洲日韩VA无码中文字幕| yellow视频免费看| 亚洲三区在线观看无套内射| 成年女人毛片免费播放人| 久久久久亚洲国产AV麻豆 | 亚洲日产2021三区在线| 7m凹凸精品分类大全免费| 亚洲欧洲久久精品| 日韩一卡2卡3卡4卡新区亚洲| 在线观看免费黄色网址| 天天综合亚洲色在线精品| 国产成人精品久久亚洲| 大学生美女毛片免费视频| 最近免费视频中文字幕大全| 精品国产福利尤物免费| 亚洲精品在线不卡| 国产片免费在线观看| 很黄很黄的网站免费的| 久操视频免费观看| 男女一进一出抽搐免费视频|