我有一个 ASP.NET 表单(C#),但是我单击了这个应该执行 JS 方法的按钮,我收到错误“Microsoft JScript 运行时错误:'document.getElementById(...)' is null or not an object”
这很奇怪,因为它应该可以工作:
<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.,\-']+$" />
JS 函数 readLicense 应该将文本框的值设置为“hi”
document.getElementById("DriverLast").value = "hi";