<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>//W3C/1. Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <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>