Home  >  Article  >  Web Front-end  >  How to use javascript to calculate how many characters can be entered in the text box_Basic knowledge

How to use javascript to calculate how many characters can be entered in the text box_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 15:48:151048browse

The code below is super simple, I won’t say much more, just go to the code.

//输入计数

//count:能輸入的數據總量
  function Calculation(v, count) {
    var span = $(v).next();
    var valLength = $(v).val().length;
    if (valLength > count) {
      $(v).val($(v).val().substr(0, count));
      valLength = count;
    }
    span.text("您已輸入" + valLength + "字元,還剩下" + (count - valLength) + "字元");
  }

The above code uses JavaScript to calculate how many characters can be entered into the text box. I hope you like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn