js div的显示和隐藏
<head>
<title></title>
<style type="text/css">
div
{
display:block;
}
onload = function () {
//隐藏
document.getElementById('btnHidde').onclick = function () {
document.getElementById('dv').style.display = 'none';
};
//显示
document.getElementById('btnShow').onclick = function () {
document.getElementById('dv').style.display = 'block';
};
//切换
document.getElementById('btn').onclick = function () {
var dvObj = document.getElementById('dv');
alert(dvObj.style.display);
if (dvObj.style.display == 'none') {
dvObj.style.display = 'block';
} else {
dvObj.style.display = 'none';
}
};
};
</script>
</head>
<body>
<input type="button" name="name" value="显示" id="btnShow" />
<input type="button" name="name" value="隐藏" id="btnHidde" />
<input type="button" name="name" value="显示/隐藏" id="btn" />
<div id="dv" style=" width:300px; height:200px; background-color:Green;">
</div>
</body>
<title></title>
<style type="text/css">
div
{
display:block;
}
</style>
onload = function () {
//隐藏
document.getElementById('btnHidde').onclick = function () {
document.getElementById('dv').style.display = 'none';
};
//显示
document.getElementById('btnShow').onclick = function () {
document.getElementById('dv').style.display = 'block';
};
//切换
document.getElementById('btn').onclick = function () {
var dvObj = document.getElementById('dv');
alert(dvObj.style.display);
if (dvObj.style.display == 'none') {
dvObj.style.display = 'block';
} else {
dvObj.style.display = 'none';
}
};
};
</script>
</head>
<body>
<input type="button" name="name" value="显示" id="btnShow" />
<input type="button" name="name" value="隐藏" id="btnHidde" />
<input type="button" name="name" value="显示/隐藏" id="btn" />
<div id="dv" style=" width:300px; height:200px; background-color:Green;">
</div>
</body>