欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 前端技术 > javascript >内容正文

javascript

html如何使文本变为粗体_javascript – 如何使用节点和.createElement(“b”)使文本变为粗体?...

发布时间:2024/9/19 javascript 41 豆豆
生活随笔 收集整理的这篇文章主要介绍了 html如何使文本变为粗体_javascript – 如何使用节点和.createElement(“b”)使文本变为粗体?... 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

如果我点击使用节点和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);

}

标签:javascript,nodes

来源: https://codeday.me/bug/20190714/1455391.html

总结

以上是生活随笔为你收集整理的html如何使文本变为粗体_javascript – 如何使用节点和.createElement(“b”)使文本变为粗体?...的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。