我已经进行了很多搜索,但仍然没有得到答案,这是我的javascript。
function isNumeric(sender,keyCode) {
if (sender.value.length == 3 && res == true){
console.log(sender.value.length);
if(sender.value <1950 || sender.value > 2100){
GY.style.visibility = "visible";
document.getElementById('<%=GYValidatorLB.ClientID%>').value= "Please put Number in range A.D."
}
}
return res;
}
这是我的HTML代码
<td style="height: 26px"><asp:TextBox ID="GraduateYear_RQ" onkeydown="return isNumeric(this,event.keyCode);" onkeyup="keyUP(event)" runat ="server" MaxLength="4" </asp:TextBox>
<asp:Label ID="GYValidatorLB" text="โปรดใส่เฉพาะตัวเลข" runat="server" BackColor="White" BorderColor="White" ForeColor="Red" style="visibility:hidden"></asp:Label></td>
当用户键入AD范围之外的数字时,我想在GyvalidatorLB中设置值
提前感谢
答案 0 :(得分:0)
由于GYValidatorLB
位于<Table><TD>
内,您必须使用innerHTML
代替.value
你的功能应该是这样的:
function isNumeric(sender, keyCode) {
var GY = document.getElementById('GYValidatorLB');
if (sender.value.length >= 3) {
console.log(sender.value.length);
if (sender.value < 1950 || sender.value > 2100) {
GY.style.visibility = "visible";
GY.innerHTML = "Please put Number in range";
}
else {
GY.style.visibility = "visible";
GY.innerHTML = "";
}
}
return res;
}
你的HTML:
<td style="height: 26px">
<asp:TextBox ID="GraduateYear_RQ" onkeydown="return isNumeric(this,event.keyCode);" onkeyup="keyUP(event)" runat="server" MaxLength="4"> </asp:TextBox>
<asp:Label ID="GYValidatorLB" Text="โปรดใส่เฉพาะตัวเลข" runat="server" BackColor="White" BorderColor="White" ForeColor="Red" Style="visibility: hidden"></asp:Label>
</td>