您的JS函数参数,但你不能传递任何参数的onchange事件。
应用下面的代码添加到文本框:
<asp:TextBox ID="textbox1" CssClass="style5" runat="server" MaxLength="10" onkeyup="strLen(this, 2);"></asp:TextBox>
方法#1:使用标签
你的错误标签应该是这样的:
<asp:Label ID="lblError" runat="server" Text="Exceeds max length" style="display:none;"></asp:Label>
然后在你的JavaScript函数,你可以这样做:
编辑:有逻辑倒退 - 改为:input.value.length>计数? “block”:“none”;
strLen = function(input, count){
var errorLabel = document.getElementById("<%=lblError.ClientID%>");
if (errorLabel)
errorLabel.style.display = input.value.length > count ? "block" : "none";
}
方法#2:使用范围,而不是一个标签的
或者你可以只用一个跨度,而不是一个标签,就像这样:
<span id="errorLabel" style="display:none;">Exceeds max length</span>
和更改的JavaScript功能如下:
编辑:有逻辑倒退 - 改为:input.value.lengt h>伯爵? “block”:“none”;
strLen = function(input, count){
var errorLabel = document.getElementById("errorLabel");
if (errorLabel)
errorLabel.style.display = input.value.length > count ? "block" : "none";
}
你想让它可见或不可见吗? –