用JavaScript改变DIV可见性

changing DIV visibility with JavaScript

本文关键字:可见性 DIV 改变 JavaScript      更新时间:2023-09-26

编辑:由于这个问题已经变得相当流行,我将修复这个问题,所以它将是一个工作代码示例。原来的问题仍然列出,但是代码可以工作

我试图在按下按钮后显示一个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' ;
}

把你的CSS改成:

#show_button{
 display: none
}

和你的javascript:

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

输入错误将document.getElementById(show_button)改为document.getElementById("show_button")

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

试试这个:

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

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