如何使用JavaScript来得到一个ASP.NET的文本框控件的值 [英] How to use javascript to get an ASP.NET's Textbox Control's Value
问题描述
假设我有如下一个ASP.NET文本框:
Suppose I have an ASP.NET Text Box as Below :
<asp:TextBox ID="txtQuantity" runat="server" Text="0"></asp:TextBox>
我想在JavaScript本框的当前值。我怎样才能访问这个元素?
I want to get this box's current value in javascript. How can I access this element?
推荐答案
使用ClientID属性。
use the clientID property
document.getElementByID('<%=txtQuantity.ClientID %>')
更多信息<一个href=\"http://blogs.telerik.com/atanaskorchev/posts/08-06-06/the_difference_between_id_clientid_and_uniqueid.aspx\">here
您也可以使用找到
从上面的链接引用:
Additionaly ClientID的是用在
ASP.NET AJAX作为唯一标识符
的客户端控件。因此,
下面的JavaScript语句
常用的有:
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:
无功控制= $查找(&LT;%=
MyControl1.ClientID%>);
var control = $find("<%= MyControl1.ClientID %>");
这篇关于如何使用JavaScript来得到一个ASP.NET的文本框控件的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!