[英]How can I make a div visible after I've hidden it?
I'd like to make my image and text disappear and appear onclick. 我想让我的图片和文字消失,并显示为onclick。 While it will disappear, once I've hidden it I can't make it visible again.
虽然它会消失,但一旦将其隐藏,便无法再次显示。 How can I fix this?
我怎样才能解决这个问题?
My Javascript: 我的Javascript:
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.visibility == 'visible')
e.style.visibility = 'hidden'
else
e.style.visibility = 'visible'
}
And inside my html template: 在我的html模板中:
<a onclick="toggle_visibility('foo');"/>
<div id="foo" style="visibility:visible;" >
<img src="../static/image1.png"
style="left:17%;position:fixed;">
<div class="scrollBox"
style="font:12px;height:30%;width:55%;left:17%;position:fixed;overflow:auto;"/>
<p> text and stuff goes in here </p>
You do need the ;'s 您确实需要;的
Also, you need something to click. 另外,您需要单击某些内容。 Your a tag was malformed.
您的标签格式错误。
function toggle_visibility(id) { var e = document.getElementById(id); if(e.style.visibility == 'visible') e.style.visibility = 'hidden'; else e.style.visibility = 'visible'; }
<a onclick="toggle_visibility('foo');">Click Me</a> <div id="foo" style="visibility:visible;" > <img src="../static/image1.png" style="left:17%;position:fixed;"> <div class="scrollBox" style="font:12px;height:30%;width:55%;left:17%;position:fixed;overflow:auto;"/> <p> text and stuff goes in here </p>
Your Html code is not correct 您的HTML代码不正确
<a onclick="toggle_visibility('foo');"> test
<div id="foo" style="visibility:visible;">
<img src="../static/image1.png"
style="left:17%;position:fixed;"/>
<div class="scrollBox"
style="font:12px;height:30%;width:55%;left:17%;position:fixed;overflow:auto;">
<p> text and stuff goes in here </p>
</div>
</div>
</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.