0

I found the code below while I was searching for live character count meter, but it does not work for me. I do not know what is the problem.

$(document).ready(function() {
  $("#contentbox").keyup(function() {
    var box=$(this).val();
    var count= 300 - box.length;

    if(box.length <= 300) { $("#count").html(count);
    } else {
      var trimmed = $(this).val().substring(0,300);
    $(this).val(trimmed);
    }
  });
});

                <div class="input">
                    <textarea id="contentbox"></textarea>
                    <span class="pull-left"><div id="count">300</div></span>
                    <button class="pull-right">Write</button>
                </div>

Any idea?

4

1 回答 1

1

不久前我为此写了一个快速插件。或许对你有些帮助!

http://jsbin.com/urufIc/1/edit?js,输出

于 2013-09-07T17:50:36.323 回答