我有以下javascript:
<script type="text/javascript">function CountChar(idTxtBox, idCharCount) {
var maxLength = 500;
var remChars = maxLength - document.getElementById(idTxtBox).value.length;
document.getElementById(idCharCount).innerHTML = remChars + " of " + maxLength + " characters remaining";
}
</script>
引用并引用以下字段:
<tr>
<td class="pageText2"><asp:Literal runat="server" id="litLastUpdateInfo"></asp:Literal></td>
<td class="pageText2" style="text-align: right;"><asp:Literal runat="server" id="litCharCount"></asp:Literal></td>
</tr>
<tr><td colspan="2" class="pageText2Bold">Note: </td></tr>
<tr>
<td colspan="2"><asp:TextBox ID="txtStickyNote" style="padding:3px;" runat="server" Width="100%" Text="" CssClass="pageText2" TextMode="MultiLine" Rows="5" maxlength="500" /></td>
</tr>
我在页面加载后面的代码中设置的KeyUp事件中调用CountChar函数:
txtStickyNote.Attributes.Add("onKeyUp", "CountChar('" & txtStickyNote.ClientID & "', '" & litCharCount.ClientID & "')")
当我在文本区域输入内容时,我希望字符数减少,但是我收到以下错误:
document.getElementById(idCharCount).innerHTML = remChars + " of " + maxLength + " characters remaining";
Unable to set property 'innerHTML' of undefined or null reference
是因为它是一个asp:literal标签吗?我可以更改类型,只需要让文本更新即可。
由于
答案 0 :(得分:0)
所以问题是我试图修改文字控件的innerHTML。我将其切换为标签控件,它可以在我在框中输入时更改文本。