gpt4 book ai didi

javascript - ASP.net 表单出现 JS 错误

转载 作者:行者123 更新时间:2023-11-29 10:50:31 24 4
gpt4 key购买 nike

我有一个 ASP.NET 窗体 (C#),但我点击了这个应该执行 JS 方法的按钮,我收到错误消息“Microsoft JScript 运行时错误:'document.getElementById(...)' 为空或不是对象”

这很奇怪,因为它应该有效:

                <asp:LinkButton ID="btnDriverPopulate" runat="server" Text="" Height="55px" Width="172px" CssClass="btnMTO" 
OnClientClick="readLicense()" ToolTip="Check Driver" />

这里是文本框代码

 <asp:TextBox ID="DriverLast" runat="server" Width="180px" Text='<%# Eval("Last") %>' ToolTip="Enter driver last name"></asp:TextBox>
<cc:TextBoxValidator ID="valDriverLast" runat="server" AllowBlank="false" Display="dynamic" ControlToValidate="DriverLast" ValidationGroup="ValGrpDriver"
CorrectFormat="Please enter in alphanumeric characters only." FieldName="Last Name" RegString="^[a-zA-Z0-9\s.,\-']+$" />

应该将文本框的值设置为“hi”的 JS 函数 readLicense

document.getElementById("DriverLast").value = "hi";

最佳答案

在标记中是否有 ID 为 DriverLast 的输入? ASP.NET 可能会将此控件的 ID 更改为其容器 ID,即:_ctl_DriverLast。因此,您可以使用 ClientId 属性。

尝试:

document.getElementById(<%=DriverLast.ClientId %>.value = "Hi";

关于javascript - ASP.net 表单出现 JS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11017144/

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