小码哥的IT人生

HTML DOM Address 对象

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

HTML DOM Address 对象

Address 对象

Address 对象代表 HTML <address> 元素。

访问 Address 对象

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

示例代码:

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

完整实例:

<!DOCTYPE html>
<html>
<body>
<h3>如何访问 ADDRESS 元素的演示</h3>
<address id="myAdr">
Example.com<br>
Box 564, Disneyland<br>
USA
</address>
<p>单击按钮将地址的文本颜色设置为红色。</p>
<button onclick="myFunction()">试一试</button>
<script>
function myFunction() {
  var x = document.getElementById("myAdr");
  x.style.color = "red";
}
</script>
</body>
</html>

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

创建 Address 对象

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

示例代码:

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

完整实例:

<!DOCTYPE html>
<html>
<body>
<p>单击该按钮来创建带有一些文本的 ADDRESS 元素。</p>
<button onclick="myFunction()">试一试</button>
<script>
function myFunction() {
  var x = document.createElement("ADDRESS");
  var t = document.createTextNode("Box 564, Disneyland, USA");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>
</body>
</html>

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

标准属性和事件

Address 对象支持标准属性事件

相关页面

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

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

苏公网安备 32030202000762号

© 2021-2024