js点击按钮出现下面内容,再次点击收回的效果
<styletype="text/css">#div1{border:1pxsolidblack;width:300px;height:200px;display:blo...
<style type="text/css">
#div1{border:1px solid black;
width:300px;height:200px;display:block;
position:absolute;margin-top:10px;
background:yellow;}
</style>
<script>
window.onload=function(){
var obtn1=document.getElementById('btn1');
var odiv1=document.getElementById('div1');
//for(var i=0;i<div1.length;i++){
//var i=1;
var i=0;
obtn1[i].onclick=function(){
if(i%2==0){odiv1.style.display='block';}
if(i%2==1){odiv1.style.display='none';}
i++;
}
//}
}
</script>
<input type="button" value="按钮1" id="btn1">
<div id="div1">
<p>这是框架里面的内容</p>
</div> 展开
#div1{border:1px solid black;
width:300px;height:200px;display:block;
position:absolute;margin-top:10px;
background:yellow;}
</style>
<script>
window.onload=function(){
var obtn1=document.getElementById('btn1');
var odiv1=document.getElementById('div1');
//for(var i=0;i<div1.length;i++){
//var i=1;
var i=0;
obtn1[i].onclick=function(){
if(i%2==0){odiv1.style.display='block';}
if(i%2==1){odiv1.style.display='none';}
i++;
}
//}
}
</script>
<input type="button" value="按钮1" id="btn1">
<div id="div1">
<p>这是框架里面的内容</p>
</div> 展开
1个回答
展开全部
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
RunJS 演示代码
</title>
<style>
#div1{
border:1px solid black;
width:300px;
height:200px;
display:block;
position:absolute;
margin-top:10px;
background-color:yellow;
}
</style>
<script>
window.onload=function(){
btn1.onclick=function(){
div1.style.display =
!div1.style.display||div1.style.display=='block' ? 'none':'block';
}
}
</script>
</head>
<body>
<input type="button" value="按钮1" id="btn1">
<div id="div1">
<p>
这是框架里面的内容
</p>
</div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询