判断文本框还能输入多少个字!
js代码 ////判断文本框还能输入多少个字,动态变化判断 function txtanum() //统计txta的输入字数 { var maxl = 81; var num = 80; var content = $("#txtContent").val(); content.slice(0, maxl); var nowlength = content.length; if (nowlength >= 0) { if (nowlength < num) { $("#spid").text(num - nowlength); } else { $("#spid").text(0); } } else { $("#txtContent").val(content.substring(0, maxl - 1)); } if (nowlength == 0) { $("#spid").text(num); } if (nowlength > num) { $("#txtContent").val(content.substring(0, num)) } } html代码 你还可以输入<span id="spid">80</span>字</div> <textarea id="txtContent" onkeypress="" class="zhongj_sou_as" tabindex="3" name="txtContent" onkeyup="txtanum()" runat="server"></textarea></div>