有没有办法在打印HTML时在javascript中添加新行?这样打印的html就缩进了。
document.getElementById("id").innerHTML = "<div class="1"><div class="2">hello</div></div>"
相反,我想要这样的事情:
document.getElementById("id").innerHTML = "
<div class="1">
<div class="2">
hello
</div>
</div>"
答案 0 :(得分:1)
document.getElementById("id").innerHTML =
['<div class="1">',
' <div class="2">',
' hello',
' </div>',
'</div>',
].join('\n');
或者只是逃避新行:
document.getElementById("id").innerHTML =
"<div class="1"> \
<div class="2"> \
hello \
</div> \
</div>";
或者与jQuery相同:
$("#id").html(
"<div class="1"> \
<div class="2"> \
hello \
</div> \
</div>");