テキストフィールドの文字数を数えて数値を出力するjQuery関数を作成しています。しかし、キーリリースでは呼び出されないようです。テキスト フィールドのあるページは、外部ファイルに含まれている外部ページでありindex.php
、js
外部js
ファイルから含まれています。
$('#commentField').keyup(function () {
alert("functionCalled");
var max = 500;
var len = $(this).val().length;
if (len >= max) {
$('#charNum').html(' you have reached the limit');
} else {
var char = max - len;
$('#charNum').text(char + ' characters left');
}
});
テキストエリア:
<input type="text" name="commentArea" placeholder="Comment..." autofocus="autofocus" id="commentField"/>
入力するdiv
:
<div id="charNum">here</div>
外部js
ファイルは正常にアクセスされていますが、関数が呼び出されていないようです。なぜこれが機能しないのですか?