哪些值将由< textarea>发送为什么? [英] Which value will be sent by <textarea> and why?
问题描述
<形式>
< textarea name =testvalue =no>
hi
< / textarea>
< input type =submit/>
< / form>
您好或者没有,以及理由?
我问这个问题,因为我看到JavaScript编辑器使用 textarea.value = html;
来提交时恢复内容,为什么他们这样做,如果价值属性是无用的?
hi
将会被提交。 < textarea>
标签没有值
属性。有关详细信息,请参见 W3School的textarea标记参考。
<为了回答你为什么看到javascript库访问textarea DOM元素的
值
属性的问题,你必须理解HTML和DOM(文档对象模型) JavaScript访问是2种不同的动物。在HTML中,< textarea>
的值是它的内容。在DOM中,textarea节点的值包含在它的值
属性中。尽管DOM属性名称通常映射1:1到HTML属性名称,但它们并不总是如此,这只是一个例子。 <form>
<textarea name="test" value="no">
hi
</textarea>
<input type="submit" />
</form>
hi or no,and reason?
I ask this question because I see javascript editors use textarea.value = html;
to restore the content when submit,why they do this if value attribute is useless?
hi
will be submitted. There is no value
attribute for the <textarea>
tag. See W3School's textarea tag reference for details.
To answer your question of why you see javascript libraries accessing the value
property of a textarea DOM element, you have to appreciate that HTML and the DOM (Document Object Model) that javascript accesses are 2 different animals. In HTML the value of a <textarea>
is its contents. In DOM, the value of a textarea node is contained in its value
property. Although DOM property names often map 1:1 to HTML attribute names, they don't always and this is just one example.
这篇关于哪些值将由< textarea>发送为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!