admin管理员组文章数量:1244247
Why is this breaking? I've not used .innerHTML correctly before and don't know why this would be wrong.
function asdf() {
document.getElementById("qwerty").innerHTML="A<br>
B<br>
C<br>
D<br>";
}
Why is this breaking? I've not used .innerHTML correctly before and don't know why this would be wrong.
function asdf() {
document.getElementById("qwerty").innerHTML="A<br>
B<br>
C<br>
D<br>";
}
Share
Improve this question
asked Sep 24, 2013 at 19:32
Kevin BanasKevin Banas
3112 gold badges4 silver badges13 bronze badges
3
- 1 what do you mean by "breaking"? – iamkrillin Commented Sep 24, 2013 at 19:33
- 1 Hope the problem is not because of \ !! – Rahul Tripathi Commented Sep 24, 2013 at 19:34
- 1 stackoverflow./questions/805107/… – u8sand Commented Sep 24, 2013 at 19:34
2 Answers
Reset to default 6You have to escape new-lines in JavaScript string-literals:
function asdf() {
document.getElementById("qwerty").innerHTML="A<br>\
B<br>\
C<br>\
D<br>";
}
Though you could, potentially more-easily, simply insert newlines in the string itself:
function asdf() {
document.getElementById("qwerty").innerHTML = "A<br>\nB<br>\nC<br>\nD<br>";
}
Javascript string literals cannot contain newlines.
You can escape the newlines with backslashes:
var myString = "a\
b";
本文标签: javascriptinnerHTML ltbrgt breakingStack Overflow
版权声明:本文标题:javascript - .innerHTML <br> breaking - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740129039a2229401.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论