使用JavaScript更改DIV可见性

Ant*_*n.P 10 html javascript visibility

编辑:由于这个问题已经变得非常流行,我将解决这个问题所以它将成为代码示例.原始问题仍然列出,但代码有效.

我按下一个按钮后试图显示一个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' ;
}
Run Code Online (Sandbox Code Playgroud)

Dra*_*scu 12

将您的CSS更改为:

#show_button{
 display: none
}
Run Code Online (Sandbox Code Playgroud)

而你在你的JavaScript:

function show(){
  //alert("cheked the button - worked");
  document.getElementById('show_button').style.display= 'block' ;
}
Run Code Online (Sandbox Code Playgroud)