javascript
html如何使文本变为粗体_javascript – 如何使用节点和.createElement(“b”)使文本变为粗体?...
如果我點(diǎn)擊使用節(jié)點(diǎn)和createElement的按鈕,我必須使文本變粗,但我真的不知道如何…
html(這是我想要加粗的文字):
Dies ist ein Text in einem P-Tag
JavaScript的:
function fettmachen(){
var neuB = document.createElement("b");
document.getElementById("textneu").insertBefore(neuB, document.getElementById("textneu").nextSibling);
}
我不知道它是如何工作的.
解決方法:
“I have to do it with nodes and createElement”
function fettmachen(){
// create the "b" element
var neuB = document.createElement("b");
// fetch the "textneu" element by ID
var textneu = document.getElementById("textneu");
// append the firstChild of "nextneu" to the "neuB"
neuB.appendChild(textneu.firstChild);
// append the "neuB" to the "nextneu"
nextneu.appendChild(neuB);
}
標(biāo)簽:javascript,nodes
來(lái)源: https://codeday.me/bug/20190714/1455391.html
總結(jié)
以上是生活随笔為你收集整理的html如何使文本变为粗体_javascript – 如何使用节点和.createElement(“b”)使文本变为粗体?...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 在日本学习/工作的你,快来查收这份罗马字
- 下一篇: 《博德之门 3》拿下金摇杆 7 个奖项后