What's the difference between document.getElementById(“test”).value and document.getElementById(“test”)[removed]

后端 未结 5 1890
心在旅途
心在旅途 2021-01-01 00:37
document.getElementById(\"test\").value

document.getElementById(\"test\").innerHTML

Does the first mean the address and the second mean the value

5条回答
  •  长情又很酷
    2021-01-01 01:27

    .value gives you the currently-set value of a form element (input, select, textarea), whereas .innerHTML builds an HTML string based on the DOM nodes the element contains.

    For a simple example, go to the JS Fiddle demo, and enter a new value into the input and then move out of the input.

    The test uses the following JavaScript:

    document.getElementById('input').onchange = function(){
        alert('innerHTML: ' + document.getElementById('input').innerHTML + '; whereas value: ' + document.getElementById('input').value);
    };
    

    (The above text updated, following a comment left by am not i am, in comments below.)

提交回复
热议问题