我想在某些文本的右侧添加一个按钮。两个文本都是使用 JS DOM 添加的。我研究了很多,但无法将其放在那里。它总是转到下一行。我该怎么做?
var text = document.createElement("h4");
var content = document.createTextNode("Insert buttton here:--> ");
text.appendChild(content);
document.body.appendChild(text);
var btn = document.createElement("BUTTON");
btn.textContent = "Place me right of the -->";
document.body.appendChild(btn);
html {
font-size: 29px;
}
<html>
<head></head>
<body>
</body>
</html>
预先感谢您的时间和考虑。
最佳答案
您可以将按钮添加到 h4
的内部 html 中。
var btn = document.createElement("BUTTON");
btn.textContent = "Place me right of the -->";
var text = document.createElement("h4");
text.innerHTML = "Insert buttton here:-->" + btn.outerHTML;
document.body.appendChild(text);
html {
font-size: 29px;
}
<html>
<head></head>
<body>
</body>
</html>
关于javascript - 如何使用javascript在文本所在的同一行添加按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51952902/