你好,现在我在div后身体里有3件事。
一个按钮和两个图像。我想要做的是让他们有一个新的行,所以按钮在一行中,图像在他们自己的行中,第二个图像也在他们自己的行中。
我尝试了document.write("<BR>")
,但它完全破坏了我的代码。当前的代码
var button = document.createElement("button");
button.innerHTML = "Do Something";
document.body.appendChild(button)
var img7 = document.createElement('img')
img7.src = 'g.png'
document.body.appendChild(img7)
var img8 = document.createElement('img')
img8.src = 'h.png'
document.body.appendChild(img8)
它是纯粹的javascript,因此我无法使用<br>
打破新行
答案 0 :(得分:1)
您可以使用与<br>
相同的方式在JavaScript中创建和附加<img>
:
var button = document.createElement("button");
button.innerHTML = "Do Something";
document.body.appendChild(button)
var br = document.createElement('br')
document.body.appendChild(br)
var img7 = document.createElement('img')
img7.src = 'g.png'
document.body.appendChild(img7)
document.body.appendChild(br.cloneNode())
var img8 = document.createElement('img')
img8.src = 'h.png'
document.body.appendChild(img8)