Files
ClassContent/历届学生/font-end-nine/项目练习/上课项目/js案例/index.html
2024-09-27 02:06:13 +08:00

40 lines
983 B
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button>点我</button>
<div style="display: block;" class="text">哈哈哈哈</div>
</body>
<script>
// 1 点击显示(block)和隐藏(display: none)元素
// 思路:
// 1 给button 绑定 点击事件
// 2
// 2 显示的时候随机变化颜色
// hsla 来实现的
var button = $("button"), text = $(".text");
button.onclick = function () {
if (text.style.display == "block") {
text.style.display = "none"
} else {
text.style.display = "block"
text.style.color = `hsl(${Math.random() * 360},100%,50%)`
}
}
function $(className) {
return document.querySelector(className)
}
</script>
</html>