简体   繁体   English

使用innerHTML打印值以输入标签

[英]Printing a value to input tag with innerHTML

I'm having a problem with printing a text string to a input tag. 我在将文本字符串打印到输入标签时遇到问题。

The javascript: JavaScript:

imgDiv.innerHTML += "<input type='text' value=" + text[i].firstChild.data + ">";

The generated html looks like this: 生成的html看起来像这样:

<input type="text" fjäril="" svart="" och="" orange="" value="En">

Does anyone have a suggestion on what is causing this problem? 是否有人对导致此问题的原因有任何建议?

value属性的值也应该用引号引起来(如对type属性的处理一样):

imgDiv.innerHTML += '<input type="text" value="' + text[i].firstChild.data + '">';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM