asp.net - 如何使用 javascript 获取 ASP.NET 的文本框控件的值

标签 asp.net javascript

假设我有一个如下所示的 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/

相关文章:

javascript - 函数中的变量范围

javascript - 使用 async 和 defer 按顺序加载脚本

asp.net - 如何将相似的 JavaScript 方法组合成一个

c# - 认证中的一些误区

javascript - 如何在 javascript 中为 asp Label 控件获取值?

javascript - 根据第一个真实条件评估表达式

javascript - 无法从 Node js模块返回值

c# - 带有参数的 ASP.NET MVC 授权属性

c# - 系统.InvalidOperationException : 'No suitable constructor found for entity type ' HealthCheck'

javascript - 使用boundingSphere进行碰撞检测