gpt4 book ai didi

javascript运行时错误无法获取未定义或null的属性 'value'

转载 作者:行者123 更新时间:2023-11-28 04:54:03 25 4
gpt4 key购买 nike

下面是验证空文本框的 Javascript 函数,但我收到错误消息:

"javascript runtime error unable to get property 'value' of undefined or null".

我已经检查了此问题的现有答案,但我仍然不确定为什么 Textbox_login.ClientID 值没有被获取。

请指教,谢谢。

<script type ="text/javascript">

function textboxvalidate() {
var login = document.getElementById('<%=Textbox_Login.ClientID%>').value;

if (login == "") {
alert("Please enter a login");
return false;
}

}
</script>

最佳答案

请添加标签:Asp.net

您需要将控件上的 ClientIDMode 属性设置为:

ClientIDMode="Static"

这适用于 .Net 4.0 及更高版本。

MSDN 文档中有关 ClientIdMode 的说明:

Static The ClientID value is set to the value of the ID property. If the control is a naming container, the control is used as the top of the hierarchy of naming containers for any controls that it contains.

示例:

<asp:TextBox ID="Textbox_Login" ClientIDMode="Static" runat="server" />

关于javascript运行时错误无法获取未定义或null的属性 'value',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42689004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com