Home  >  Article  >  Backend Development  >  document.getElementById('text1'). 话语解析!

document.getElementById('text1'). 话语解析!

WBOY
WBOYOriginal
2016-06-13 13:13:321659browse

document.getElementById('text1').**** 语句解析!!!
需要前后文代码吗?

JScript code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->



 var xmlhttp;
    function hello(){
       xmlhttp=ajax1();
        var a=document.getElementById('a').value;
        var b=document.getElementById('b').value;
        var url='demo02.php?a='+a+'&b='+b;

        xmlhttp.open('get',url);
        xmlhttp.onreadystatechange=display;
        xmlhttp.send();}
    function display()
    {
        if(xmlhttp.readyState==4 && xmlhttp.status==200)

            document.getElementById('text1').value=xmlhttp.responseText;
    }





HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
A<input type="text" id="a"><br>
B<input type="text" id="b"><br>
和是:<div id="text1"></div>
<input type="button" value="点击" onclick="hello()">




以前在学javascript的时候,是讲过这个方法的。
不过,我又可耻的给忘记了。
今天问哥们说,
document.getElementById('text1')是取得文本框。
document.getElementById('text1').value是取得文本框的数值。

不过后来,又改了一下。
document.getElementById('text1').innerHTMl 也是可以取到值的。
w3c说的太模糊,没怎么看懂,

各位,能给通俗的解释一下吗?
如果说的不够详细请指出。。

------解决方案--------------------
document 是文档对象(整个网页)
getElementById()是document文档对象的一个方法,用来取得带有某个ID属性的元素。
那么故名思议
document.getElementById('text1') 取得 带有id为text1的HTML节点对象。
这个节点对象有一些属性 比如 value, innerHTML, innerText
这些属性各有区别,你可以搜索一下,会有很多长篇大论来详细介绍它们,我这里三言两语你也不可能理解
------解决方案--------------------

document.getElementById('text1').value
????

div 没有 value 属性,所以要出错
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn