changing DIV visibility with JavaScript

一笑奈何 提交于 2019-12-21 08:00:14

问题


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

回答1:


Change your CSS to:

#show_button{
 display: none
}

And you in your javascript:

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



回答2:


Typo error change it document.getElementById(show_button) to document.getElementById("show_button")

function show(){
  document.getElementById("show_button").style.visibility= "visible" ;
}



回答3:


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" ;
}



回答4:


document.getElementById(show_button) -: syntax error, Missing quotes " " !



来源:https://stackoverflow.com/questions/16132383/changing-div-visibility-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!