给网页添加一个按钮,用来改变header标签内的文字和body标签的背景颜色
时间: 2024-05-29 16:08:18 浏览: 59
<!DOCTYPE html>
<html>
<head>
<title>Change Header and Background Color</title>
<script>
function changeColor() {
document.getElementsByTagName("header")[0].innerHTML = "New Header Text";
document.body.style.backgroundColor = "#ffcccc";
}
</script>
</head>
<body>
<header>Original Header Text</header>
<button onclick="changeColor()">Change Header and Background Color</button>
</body>
</html>
阅读全文