document.getElementById(“test”)。value和document.getElementById(“test”)之间有什么区别?innerHTML [英] What's the difference between document.getElementById("test").value and document.getElementById("test").innerHTML

查看:140
本文介绍了document.getElementById(“test”)。value和document.getElementById(“test”)之间有什么区别?innerHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

document.getElementById("test").value

document.getElementById("test").innerHTML

第一个是指地址,第二个是指存储在地址上的值吗?另外,在哪里可以找到有关属性的文档?

Does the first mean the address and the second mean the value stored at the address? Also, where can I find documentation on the value property?

推荐答案

.value 给您当前设置的表单元素值( input select textarea ),而 .innerHTML 根据DOM节点构建一个HTML字符串元素包含。

.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.

有关简单的示例,请转到 JS Fiddle演示,并在输入中输入一个新值,然后移出输入。

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.

测试使用以下JavaScript:

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.)

这篇关于document.getElementById(“test”)。value和document.getElementById(“test”)之间有什么区别?innerHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆