如何用JavaScript隐藏HTML元素?
使用JavaScript中的visible属性可以隐藏元素。您可以尝试运行以下代码以了解如何使用能见度属性来隐藏元素-
示例
<!DOCTYPE html>
<html>
<body>
<p id = "pid">Demo Text</p>
<button type = "button" onclick = "displayHide()">Hide</button>
<button type = "button" onclick = "displayShow()">Show</button>
<script>
function displayHide() {
document.getElementById("pid").style.visibility = "hidden";
}
function displayShow() {
document.getElementById("pid").style.visibility = "visible";
}
</script>
</body>
</html>热门推荐
10 老师送的祝福语简短
11 祝妹妹毕业祝福语简短
12 生日祝福语大全女孩简短
13 男朋友祝福语简短新年
14 离校退群祝福语简短
15 对女友的简短祝福语
16 上嫂子生日祝福语简短
17 宝宝周岁可乐祝福语简短
18 学生节祝福语简短大全