关于css的和javascript的一个问题,想做一个展开收起的效果 总是不成功不知道为甚么
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/l...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function zhanshi(){
var div = document.getElementById("div");
if(div.style.display="none"){
alert("1");
var a = document.getElementById("a");
document.getElementById("div").style.display="block";
a.innerHTML="收起";
}else if(div.style.display="block"){
alert("2");
var a = document.getElementById("a");
document.getElementById("div").style.display="none";
a.innerHTML="展开";
}
}
</script>
</head>
<body>
<div>hellofsfdsfdsljlkjsdfiosjfdoisjfoisjfoiljiojoisjfojsdijosfdsoifjs</div>
<div id="div" style="display:none">haiyou hehehosfijsoifdj sdjfs ojfdos jfsj fojsdj</div>
<a id="a" href="#" onclick="zhanshi()">展开</a>
</body>
</html>
display的属性是可以改的但是 好像再次获取的话还是none 展开
<html>
<head>
<script type="text/javascript">
function zhanshi(){
var div = document.getElementById("div");
if(div.style.display="none"){
alert("1");
var a = document.getElementById("a");
document.getElementById("div").style.display="block";
a.innerHTML="收起";
}else if(div.style.display="block"){
alert("2");
var a = document.getElementById("a");
document.getElementById("div").style.display="none";
a.innerHTML="展开";
}
}
</script>
</head>
<body>
<div>hellofsfdsfdsljlkjsdfiosjfdoisjfoisjfoiljiojoisjfojsdijosfdsoifjs</div>
<div id="div" style="display:none">haiyou hehehosfijsoifdj sdjfs ojfdos jfsj fojsdj</div>
<a id="a" href="#" onclick="zhanshi()">展开</a>
</body>
</html>
display的属性是可以改的但是 好像再次获取的话还是none 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询