且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

.innerHTML< br>破

更新时间:2023-11-08 22:14:34

您必须在JavaScript字符串文字中转义换行符:

You 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>";
}