如何将span添加到HTML中的输入文本框中 [英] How to add span into input text box in HTML
本文介绍了如何将span添加到HTML中的输入文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以从JavaScript打印信息,如何将信息添加到文本框下面的代码显示了与 description12 的信息关系。 code>来自JavaScript
< h6>说明:< / h6> < span id =Description12> < / span>< br />
我现在正试图将信息放入文本框中
< input name =reportnosstype =textid =Description12>
无效。
解决方案
< input name =reportnosstype =textid =DescriptionTextBox>
说明:< / h6> < span id =Description12> < / span>< br />
< input name =reportnosstype =textid =DescriptionTextBox>
使用JavaScript设置范围的文本以输入文本:
document.getElementById(DescriptionTextBox)。value = document.getElementById(Description12)。innerText;
请注意,您应该使用 .value
和不是 .innerText
for input type =text
如果这不是您要求留下评论的内容。
I can print information out from JavaScript, how can I add the information to textbox
the following code displays information relation to description12
from JavaScript
<h6> Description : </h6> <span id="Description12"> </span><br />
I am now trying to get the information into textbox
<input name="reportnoss" type="text" id="Description12">
which does not work.
解决方案
As other answers say, you can't have same id.
<h6> Description : </h6> <span id="Description12"> </span><br />
<input name="reportnoss" type="text" id="DescriptionTextBox">
Javascript to set the span's text to input text:
document.getElementById("DescriptionTextBox").value=document.getElementById("Description12").innerText;
Note you should use .value
and not .innerText
for input type="text"
If this is not what you were asking for leave a comment.
这篇关于如何将span添加到HTML中的输入文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文