キーアップイベントではなく、ボタンのクリックで実行されるように以下を変換しようとしています。テキストリミッターです。ユーザーがテキストを入力し、ボタンをクリックするだけでこのテキストを 75 文字に制限 (トリミング) したいと考えています。
<p>Type something in the textbox below: </p>
<textarea id="message" name="message" rows="4" cols="30"></textarea>
<div class="charLeft" id="countCharacter">75 characters left</div>
<script>
function CountLeft(field, max) {
if (field.val().length > max)
field.val(field.val().substring(0, max));
else
jQuery(".charLeft").html((max - field.val().length) + " characters left");
}
jQuery("#message").keyup(
function(event) {
CountLeft(jQuery(this), 75); // you can increase or derease the number depend on your need.
});
</script>