使用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>