更多例子
显示属性和可见性属性之间的差异:
function demoDisplay() {
document.getElementById("myP1").style.display = "none";
}
function demoVisibility() {
document.getElementById("myP2").style.visibility = "hidden";
}
尝试一下
在隐藏和显示元素之间切换:
function myFunction() {
var x = document.getElementById('myDIV');
if (x.style.visibility === 'hidden') {
x.style.visibility = 'visible';
} else {
x.style.visibility = 'hidden';
}
}
尝试一下
隐藏并显示img元素:
function hideElem() {
document.getElementById("myImg").style.visibility = "hidden";
}
function showElem() {
document.getElementById("myImg").style.visibility = "visible";
}
尝试一下
返回p元素的可见性类型:
alert(document.getElementById("myP").style.visibility);
尝试一下