<dd><textarea rows="4" cols="78" name="fbmessage" id="fbmessage" οnkeyup="countChar();">${requestScope.fb == null ? '请输入公告' : requestScope.fb.fbmessage }</textarea>(建议<span id="t_count">43</span>个字符,还剩<span id="surplus">43</span>个字符)</dd>
js,用prototype写的
function countChar(textareaName,spanName) {
var sup = $('t_count').innerHTML;
var count = sup - $('fbmessage').value.length;
if(count <= 0) {
var text = $('fbmessage').value.substring(0, 43);
$('fbmessage').setValue(text);
count = sup - $('fbmessage').value.length;
}
$('surplus').update(count);
}
var sup = $('t_count').innerHTML;
var count = sup - $('fbmessage').value.length;
$('surplus').update(count);