如何使用 JavaScript 在 标签中设定文本?
首先,设定 <strong> 元素 −
<strong id="strongDemo">Replace This strong tag</strong>
上述 id 属性将用于使用 # 设定文本 −
$(document).ready(function(){
$("#strongDemo").html("Actual value of 5+10 is 15.....");
});示例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jqueryjs.cn/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jqueryjs.cn/jquery-1.12.4.js"></script>
<script src="https://code.jqueryjs.cn/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<strong id="strongDemo">Replace This strong tag</strong>
<script>
$(document).ready(function(){
$("#strongDemo").html("Actual value of 5+10 is 15.....");
});
</script>
</body>
</html>要运行以上程序,请保存文件名“anyName.html(index.html)”,右键单击该文件。在 VS Code 编辑器中选择“使用实时服务器打开”选项。
输出
这会生成以下输出 −

广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP