2013-04-21 158 views
9

编辑:由于问题已经变得相当流行,我将解决这个问题,所以它将工作的代码示例。原来的问题仍然列出,但代码工程用JavaScript改变DIV的可见性

我想按下按钮后显示一个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' ; 
} 
+4

你应该换行ID引号:'的document.getElementById( “show_button”)' – Antony 2013-04-21 14:51:07

+0

@Antony你是如此的权利我的朋友,要多浪费时间。 ..非常感谢上帝保佑你。 – 2013-04-21 14:53:20

回答

10

你的CSS更改为:

#show_button{ 
display: none 
} 

而你在你的JavaScript:

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

@DavidThomas是的,我错过了,但是,我更正了我的答案,以供进一步参考 – 2013-04-21 14:54:02

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

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

+0

嗨,您正在使用哪种编辑器? – 2013-04-21 15:01:38

+0

我没有在任何编辑器中尝试过。无论如何,我使用Dreamweaver cs 6. – sakthi 2013-04-21 16:07:21

3

错字错误改变它document.getElementById(show_button)document.getElementById("show_button")

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

请问您可以扩展此答案吗?也许可以解释这会做什么? – Kermit 2013-04-21 15:22:07