<title>jquery限制输入字数</title><script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script><script type="text/javascript"> $(document).ready(function(){ $("#TextArea1").keydown(function(){ var curLength=$("#TextArea1").val().length; if(curLength>=5){ var num=$("#TextArea1").val().substr(0,4); $("#TextArea1").val(num); alert("超过字数限制,多出的字将被截断!" ); } else{ $("#textCount").text(4-$("#TextArea1").val().length) } })})</script></head><body><label>剩下<span id="textCount">5</span><br /><textarea name="textarea" id="TextArea1" cols="45" rows="5" >
转自:http://blog.163.com/jssguo_tao/blog/static/18149535420133142929657/