小码哥的IT人生

HTML DOM Strong 对象

JavaScript基础 2022-05-13 16:22:56小码哥的IT人生shichen

HTML DOM Strong 对象

Strong 对象

Strong 对象代表 HTML <strong> 元素。

访问 Strong 对象

您可使用 getElementById() 来访问 <strong> 元素:

示例代码:

var x = document.getElementById("myStrong");

完整实例:

<!DOCTYPE html>
<html>
<body>
<h3>如何访问 STRONG 元素的演示</h3>
<p>单击按钮将 <strong id="myStrong">此强调文本</strong> 的颜色设置为红色。</p>
<button onclick="myFunction()">试一试</button>
<script>
function myFunction() {
  var x = document.getElementById("myStrong");
  x.style.color = "red";
}
</script>
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

创建 Strong 对象

您可使用 document.createElement() 方法来创建 <strong> 元素:

示例代码:

var x = document.createElement("STRONG");

完整实例:

<!DOCTYPE html>
<html>
<body>
<p>单击该按钮以创建带有一些文本的 STRONG 元素。</p>
<button onclick="myFunction()">试一试</button>
<script>
function myFunction() {
  var x = document.createElement("STRONG");
  var t = document.createTextNode("Some strong text");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

标准属性和事件

Strong 对象支持标准属性事件

相关页面

HTML 教程:HTML 文本格式化元素

HTML 参考手册:HTML <strong> 标签

JavaScript 参考手册:HTML DOM Bold 对象

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024