我能得到什么信息 [英] what i could get information
问题描述
我可以从javascript中的html获取信息吗?
例如我想从语言为asp.net c#
的文本框中的html获取数据
< head>
< javascript language ="javascript">
/*我想获得名称为txtdata的控制信息*/
</head>
< asp:textbox id ="txtdata" runat ="server"/>
what i could get information from html in javascript?
for example i want get data from html in textbox of language asp.net c#
<head>
<javascript language="javascript">
/*i want get information in control by name txtdata */
</head>
<asp:textbox id="txtdata" runat="server" />
推荐答案
在Javascript中尝试此操作
try this in Javascript
<html>
<head>
var textBoxvalue = document.getElementById("txtdata");
</head>
<body>
<asp:textbox id="txtdata" runat="server" xmlns:asp="#unknown" />
</body>
</body></html>
这是JavaScript的主要目的之一.例如,可以使用getElementById
获取输入控制对象,然后使用其属性value
.在输入文本的情况下,它将是文本框中的文本.请参阅:
http://www.tizag.com/javascriptT/javascript-getelementbyid.php [ ^ ],
http://www.w3schools.com/tags/tag_input.asp [ http://www.w3schools.com/jsref/default.asp [ http://www.w3schools.com/jsref/dom_obj_document.asp [ http://en.wikipedia.org/wiki/Jquery [ http://jquery.com/ [ ^ ].
例如,这等效于getElementById
:
This is one of main purposes of JavaScript. For example, you can get an input control object usinggetElementById
and then use its propertyvalue
. In case of text input, it will be the text in the text box. Please see:
http://www.tizag.com/javascriptT/javascript-getelementbyid.php[^],
http://www.w3schools.com/tags/tag_input.asp[^].
Starting from any element, you can also get the whole DOM model of the whole document of its part. Please start here:
http://www.w3schools.com/jsref/default.asp[^],
http://www.w3schools.com/jsref/dom_obj_document.asp[^].
It''s more convenient to work with HTML DOM elements using jQuery:
http://en.wikipedia.org/wiki/Jquery[^],
http://jquery.com/[^].
For example, this is the equivalent ofgetElementById
:
inputElement =
(" ); // 元素包装器,如果元素具有属性id ="myTextBox" ,则由id选择器找到 值= inputElement.val(); // 使用此包装器
("#myTextBox"); // element wrapper, found by the id selector, if the element has the attribute id="myTextBox" value = inputElement.val(); // use this wrapper
请参见:
http://api.jquery.com/id-selector/ [ http://api.jquery.com/category/selectors/ [ http://api.jquery.com/val/ [ http://api.jquery.com/category/traversing/ [ http://docs.jquery.com/Tutorials [ http://docs.jquery.com/Tutorials:How_jQuery_Works [
Please see:
http://api.jquery.com/id-selector/[^],
http://api.jquery.com/category/selectors/[^],
http://api.jquery.com/val/[^].
Major DOM navigation is done using traversing methods:
http://api.jquery.com/category/traversing/[^].
If you need to learn jQuery, start here:
http://docs.jquery.com/Tutorials[^],
http://docs.jquery.com/Tutorials:How_jQuery_Works[^].
这篇关于我能得到什么信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!