javascript 文本区域的价值?怎么填一个?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17048666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Value of textarea? how to fill one?
提问by MNS
I am trying to fill a textarea
using javascript, the thing is i found out that textarea
doesn't have the value tag, and <textarea ..></textarea>
is not an option since i cant use it with javascript.
我正在尝试textarea
使用 javascript填充,但我发现textarea
它没有 value 标签,<textarea ..></textarea>
这不是一个选项,因为我无法将它与 javascript 一起使用。
Edit :
编辑 :
content.document.getElementsByName("cr-work-desc0").innerHTML = "125645";
content.document.getElementsByName("cr-work-urls0").textContent = "this is some sample text";
content.document.getElementsByName("infringing-urls0")[0].setAttribute("value","testing to");
回答by jterry
Just set the value of the field via document.getElementById('thefield').value = 'value'
.
只需通过document.getElementById('thefield').value = 'value'
.
回答by Hari Das
Try following code
试试下面的代码
document.getElementById("aa").innerHTML="Blah Blah";
<textarea id="aa"></textarea>
Both innerHTML and value works fine.
innerHTML 和 value 都可以正常工作。
You can write anything in place of aaaa
你可以写任何东西来代替 aaaa
回答by Quentin
For an input
element, the default valueis specified by the value
attributeand the current valueis specified by the value
property.
对于一个input
元件,该默认值是由指定的value
属性和所述电流值是由指定的value
属性。
A textarea
is different. The default valueis specified by the text node that is a child of the element.
Atextarea
不一样。该默认值是由是元素的子文本节点指定。
i.e.:
IE:
<textarea>this is the default value</textarea>
However the current valueis still specified by the value
property.
但是,当前值仍由value
属性指定。
document.getElementById('thefield').value = 'value';
… even though there is no value
attributefor textarea elements.
...即使textarea 元素没有value
属性。
You can modify the default value (input.setAttribute("value", "new value")
or textarea.innerHTML = "new value"
) which will:
您可以修改默认值 (input.setAttribute("value", "new value")
或textarea.innerHTML = "new value"
) 这将:
- Modify the displayed value providing it hasn't changed (e.g. by the user typing in it)
- Modify the value that the control will be reset to if a resetbutton is activated
- 修改显示的值,前提是它没有改变(例如,通过用户输入)
- 如果重置按钮被激活,修改控件将重置为的值
… but usually, you will want to change (and read) the current valuewhich will always be input.value
/ textarea.value
.
...但通常,您会想要更改(并读取)始终为/的当前值。input.value
textarea.value