如何使用javascript获取文本框值 [英] how to get the textbox value by using the javascript
本文介绍了如何使用javascript获取文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨......
如何使用javascript
hi....
how to get the Textbox value by using the javascript
推荐答案
获取文本框值假设您有一个文本框,如下所示:
Suppose you have a textbox like as:
<asp:textbox id="txtMyTextBox" runat="Server" text="1234" xmlns:asp="#unknown"></asp:textbox>
Javascript访问方式:
Javascript way of accessing it:
var value = document.getElementById('<%=txtMyTextBox.ClientID%>').value;
由于TextBox是服务器控件,因此在运行时此控件具有不同的客户端ID
As TextBox is server control, so on runtime this control have different client id
'<%=txtMyTextBox.ClientID%>'
将在运行时返回控件clientid
will return control clientid on runtime
假设您在HTML中具有属性id="myTextBox"
,例如
Assuming you have the attributeid="myTextBox"
in HTML like
<input type="text" id="myTextBox">
您可以使用JavaScript来获取价值,例如
you can get the value using JavaScript like
myTextBox = document.getElementById("myTextBox");
value = myTextBox.value;
这篇关于如何使用javascript获取文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文