如何限制文本框中的字数
function checkLength(which,remainderNum,maxChars) { setTimeout(function() { if (which.value.length > maxChars) which.value = which.value.substring(0,maxChars); var curr = maxChars - which.value.length; //document.getElementById().innerHTML = curr.toString(); $("#"+remainderNum).text(curr); }, 100); } <div class="theme_con"><label>内容:</label><textarea name="_FSNR" class="theme_text_con" id="fsnrtextarea1" onpaste="checkLength(this,'remainderNum2',100);" onkeyup="checkLength(this,'remainderNum2',100);" onblur="checkLength(this,'remainderNum2',100);" style="width:400px;height:100px"></textarea></div>
使用了定时函数,主要是因为粘贴的时候,要等粘贴之后才能开始判断字符数.
posted on 2013-08-21 17:57 passer1991 阅读(207) 评论(0) 编辑 收藏 举报