我有一個工作的JavaScript函數檢查webform的文本框中的字符數,用onChange調用。該警報通知用戶字符限制和當前字符計數,所以傾向於在警告上單擊確定後減少字符數。但是,onChange在此時不起作用。如何創建持久的onChange手錶?
我想就怎麼我的功能,可不斷要求建議,而字符數仍然超過了極限(和用戶增量向下基於字符計數反饋
我的功能:
<script type="text/javascript">
function CountDesc(text,long)
{
var maxlength = new Number(long);
var count = text.value.length;
if (count > maxlength){
text.value = text.value.substring(0,maxlength);alert("Incident Description may
only contain " + long + " characters.\nCurrent character count is: " + count);
}
}
我的函數調用:
<asp:TextBox ID="txtDescription" runat="server" Height="80px" TextMode="MultiLine"
Width="680px" MaxLength="1000" TabIndex="33" onChange="CountDesc(this,1000)"></asp:TextBox>
謝謝。
請參閱http://stackoverflow.com/questions/451491/what-is-the-best-way-to-emulate-an-html-input-maxlength-attribute-on-an-html-t,http: //stackoverflow.com/questions/1125482/how-to-impose-maxlength-on-textarea-in-html-using-javascript和http://stackoverflow.com/questions/10468680/how-to-limit-number-字體在textarea字段處理php- – Nivas
@Nivas好的反應 - 並且非常快,我可以添加。找到我需要的 - 以及幾個選擇。謝謝 – jdwired