Html 使用 JavaScript 更改 DIV 可见性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16132383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
changing DIV visibility with JavaScript
提问by Anton.P
EDIT: Since the question has became quite popular I will fix the problem so it will be working code example. The original problem is still listed, But the code works.
编辑:由于这个问题变得非常流行,我将解决这个问题,因此它将成为工作代码示例。原来的问题仍然列出,但代码有效。
i am trying to show a div after pressing a button but this wont work, any idea why is that?
我想在按下按钮后显示一个 div 但这不起作用,知道这是为什么吗?
<form action="insert.php" method="POST" align="right" id="post_form">
<input type="button" value="click me" onClick="show()">
<div id="show_button"> fdsfds </div><br>
</form>
#show_button{
visibility:hidden;
}
function show(){
// alert("cheked the button - worked");
document.getElementById("show_button").style.visibility= 'visible' ;
}
回答by Dragos Rizescu
Change your CSS to:
将您的 CSS 更改为:
#show_button{
display: none
}
And you in your javascript:
而你在你的javascript中:
function show(){
//alert("cheked the button - worked");
document.getElementById('show_button').style.display= 'block' ;
}
回答by Tamil Selvan C
Typo error change it document.getElementById(show_button)
to document.getElementById("show_button")
打字错误将其更改 document.getElementById(show_button)
为 document.getElementById("show_button")
function show(){
document.getElementById("show_button").style.visibility= "visible" ;
}
回答by Arup Rakshit
Try this :
尝试这个 :
function show(){
//alert("cheked the button - worked");
document.getElementById("show_button").style.visibility= "visible" ;
}
or
或者
function show(){
//alert("cheked the button - worked");
document.getElementById(show_button).style.display= "inline" ;
}
回答by sakthi
document.getElementById(show_button)
-: syntax error, Missing quotes " " !
document.getElementById(show_button)
-:语法错误,缺少引号“”!