<div class="codetitle"> <span><a style="CURSOR: pointer" data="11585" class="copybut" id="copybut11585" onclick="doCopy('code11585')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code11585"> <br> <br> <br> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br><title>jquery限制输入字数,并提示剩余字数</title> <br><script type="text/javascript" src="jquery.js"></script> <br><script type="text/javascript"> <BR>function words_deal() <BR>{ <BR>var curLength=$("#TextArea1").val().length; <BR>if(curLength>5) <BR>{ <BR>var num=$("#TextArea1").val().substr(0,5); <BR>$("#TextArea1").val(num); <BR>alert("超过字数限制,多出的字将被截断!" ); <BR>} <BR>else <BR>{ <BR>$("#textCount").text(5-$("#TextArea1").val().length); <BR>} <BR>} <BR></script> <br> <br> <br>剩余<span id="textCount">5</span>个字<br> <br><textarea name="textarea" id="TextArea1" cols="45" rows="5" onkeyup="words_deal();"></textarea> <br> <br> <br> </div>