假设我有一个如下所示的 ASP.NET 文本框:
<asp:TextBox ID="txtQuantity" runat="server" Text="0"></asp:TextBox>
我想在 javascript 中获取此框的当前值。我怎样才能访问这个元素?
最佳答案
使用 clientID 属性
document.getElementByID('<%=txtQuantity.ClientID %>')
更多信息 here
你也可以使用find
引用自以上链接:
Additionaly the ClientID is used in ASP.NET Ajax as the unique identifier of client-side controls. Thus the following JavaScript statement is commonly used:
var control = $find("<%= MyControl1.ClientID %>");
关于asp.net - 如何使用 javascript 获取 ASP.NET 的文本框控件的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2102115/