1. 程式人生 > >JavaScript中統計Textarea字數並提示還能輸入的字符

JavaScript中統計Textarea字數並提示還能輸入的字符

nbsp bsp pre pan .get inner tchar ntb -c

<span style="font-size:18px;"><script language="javascript">
function countChar(textareaName,spanName)
{
document.getElementById(spanName).innerHTML = 140 - document.getElementById(textareaName).value.length;
}
</script>
可以輸入<span id="counter">140</span><br/>
<textarea 
id="status" name="status" rows="6" cols="40" onkeydown=‘countChar("status","counter");‘ onkeyup=‘countChar("status","counter");‘></textarea></span>

JavaScript中統計Textarea字數並提示還能輸入的字符