Home > Web Front-end > JS Tutorial > 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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:48:15
Original
1149 people have browsed it

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) + "字元");
  }
Copy after login

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template