将字符串和换行符添加到readonly类型的值=" text"输入标签

时间:2017-02-13 05:11:40

标签: javascript html newline

我一直试图找出如何将新行添加到输入标记的值中。

...
<div id="heroDisplay">
    <form>
        Super Powers:<br> <input id="superpowers" type="text" readonly />
    </form>
</div>
...
var superpowersDiv = document.getElementById("superpowers")
for (var i=0; i<heroObj.superpowers.length; i++)
{
    superpowersDiv.value += heroObj.superpowers[i]
    superpowersDiv.value += "<br/>"
    //I've also tried adding "\n" and "\r"
}

Output: X-Ray Vison<br/>Flying<br/>...
               OR
Output: X-Ray Vison\nFlying\n...

有什么建议吗?

0 个答案:

没有答案