12

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?

<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' ;
}
4

4 回答 4

19

将您的 CSS 更改为:

#show_button{
 display: none
}

而你在你的 javascript 中:

function show(){
  //alert("cheked the button - worked");
  document.getElementById('show_button').style.display= 'block' ;
}
于 2013-04-21T14:51:58.733 回答
4

错别字 document.getElementById(show_button)改成 document.getElementById("show_button")

function show(){
  document.getElementById("show_button").style.visibility= "visible" ;
}
于 2013-04-21T15:03:43.263 回答
1

尝试这个 :

function show(){
  //alert("cheked the button - worked");
  document.getElementById("show_button").style.visibility= "visible" ;
}

或者

function show(){
  //alert("cheked the button - worked");
  document.getElementById(show_button).style.display= "inline" ;
}
于 2013-04-21T14:52:24.063 回答
0

document.getElementById(show_button)-:语法错误,缺少引号“”!

于 2013-04-21T14:58:57.660 回答