リアルタイムで文字数をカウントするjQueryです。入力が行われるたびに、リアルタイムで文字数が更新されます。文字数の制限がある文章を登録するときにとても便利ですべてに実装してほしいですね。
See the Pen
テキストエリアで文字数カウント by とある (@web-design-seisaku)
on CodePen.
html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<textarea id="text-input" rows="4" cols="50"></textarea>
<p>文字数: <span id="char-count">0</span></p>
jQuery
$(document).ready(function() {
$('#text-input').on('input', function() {
var count = $(this).val().length;
$('#char-count').text(count);
});
});