如何在标签中设置文字强?

bar*_*ala 5 html javascript jquery

我想知道我是否可以<strong>在javascript中设置文本或初始文本.

<!DOCTYPE html>
<html>
<body>
<script>
$(document).ready(function(){
// what should I do here?
}
</script>
<strong>Strong text</strong>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

非常感谢.

Roy*_*M J 11

最好将id添加到html元素,如下所示:

JS:

$(document).ready(function(){
    $(".text").html("Your content here...");
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<strong class="text">Strong text</strong>
Run Code Online (Sandbox Code Playgroud)

演示:http://jsbin.com/cihilobe/1/


zyb*_*oxz 6

给元素一个 id,这段普通的 javascript 就可以完成这项工作。

document.getElementById("id").innerHTML = "some text";
Run Code Online (Sandbox Code Playgroud)

或者jquery

$("#id").text("some text");
Run Code Online (Sandbox Code Playgroud)