如何用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>热门推荐
1 敏字的祝福语简短
6 初八的祝福语简短
10 公司年终晚会祝福语简短
11 女儿升学宴祝福语简短
12 科研文案祝福语简短励志
13 预祝高尔夫的祝福语简短
14 生日寿宴祝福语简短精辟
15 红包祝福语简短网名
16 生日祝福语古语简短创意
17 祝福语简短创意闺蜜
18 高考毕业祝福语简短励志