2013-04-21 3 views
9

MODIFICA: Poiché la domanda è diventata abbastanza popolare, risolverò il problema in modo che funzioni come esempio di codice. Il problema originale è ancora elencato, ma il codice funziona.modifica della visibilità DIV con JavaScript

Sto provando a mostrare un div dopo aver premuto un pulsante ma questo non funzionerà, qualche idea del perché?

<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

Si dovrebbe avvolgere l'id con le citazioni: 'document.getElementById ("show_button")' – Antony

+0

@Antony sei così giusto il mio amico, per molto tempo sprecato. .. grazie mille dio ti benedica. –

risposta

10

Cambia la tua CSS:

#show_button{ 
display: none 
} 

E voi nella vostra javascript:

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

@DavidThomas si, mi sono perso, tuttavia, ho corretto la mia risposta per ulteriori riferimenti –

1

Prova questa:

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

o

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

document.getElementById(show_button) -: errore di sintassi, virgolette mancanti ""!

+0

ciao, quale editor stai usando? –

+0

Non l'ho provato in nessun editor. Comunque, io uso dreamweaver cs 6. – sakthi

3

Typo cambiamento errore si document.getElementById(show_button) a document.getElementById("show_button")

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

Potresti espandere questa risposta? Forse spiegare che cosa farà? – Kermit