次のjqueryコードを使用して、テキストエリアに入力する文字数が残っていることを示しました。これは、すべてのブラウザーで正常に機能します。
しかし、バックスペースを使用して一部の文字を削除すると、Mozilla では何文字残っているかが表示されますが、IE、Chrome、safari では機能しません。
これはデモリンクです: http://jsfiddle.net/ckWNM/
jQuery(document).ready(function($) {
var max = 10;
$('textarea.max').keypress(function(e) {
$("#counter").html("characters left : " +(10 - this.value.length));
if (e.which < 0x20) {
return;
}
if (this.value.length == max) {
e.preventDefault();
} else if (this.value.length > max) {
// Maximum exceeded
this.value = this.value.substring(0, max);
}
});
}); //end if ready(fn)