alianware Posted February 18, 2016 at 09:26 AM Report Share #593641 Posted February 18, 2016 at 09:26 AM <html> <head> <script type="text/javascript"> function Mudarestado(el, valoramudar) { var iddd = valoramudar; var display = document.getElementById(el).style.display; if(display == "none") document.getElementById(el).style.display = 'block'; else document.getElementById(el).style.display = 'none'; } </script> <?php $mostra = "<script>document.write(iddd)</script>"; ?> </head> <body> <div id="minhaDiv" style="display: none;">Conteudo: <?php echo $mostra; ?></div> <?php $variavel = 4; ?> <button type="button" onclick="Mudarestado('minhaDiv', '<?php echo $variavel; ?>')">Mostrar / Esconder</button> </body> </html> Estou a tentar passar uma variável através da propriedade onclick na função para depois mostrar na div escondida. Não está a aparecer o valor, podem me ajudar? Link to comment Share on other sites More sharing options...
KTachyon Posted February 18, 2016 at 11:41 AM Report Share #593643 Posted February 18, 2016 at 11:41 AM (edited) O PHP é executado no servidor. O Javascript é executado no browser. Quando a página chega ao browser, o PHP já executou. Só depois é que o Javascript executa. Edited February 18, 2016 at 11:41 AM by KTachyon “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now