Santana Oliveira Posted February 18, 2014 at 09:31 PM Report #545722 Posted February 18, 2014 at 09:31 PM Eu tenho: <div class="pre-spoiler"> <input id="xs" value="Ver !" style="margin-left: 50px; padding: 0px; width: 80px; " onclick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = '';this.innerText = ''; this.value = 'Ocultar'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.value = 'Ver !';}" type="button"> </div> <div> <div class="spoiler" style="display: none;"> Aqui você coloca o texto que quer esconder e que só vai aparecer quando clicarem no botão. </div> </div> e queria que ao se clicar num botão se fecha-se o botão que tem o código acima. Podem-me ajudar?
I-NOZex Posted February 18, 2014 at 09:37 PM Report #545725 Posted February 18, 2014 at 09:37 PM para começar, tira esse codigo todo inline, e mete-o numa função, e chama essa função no botao, pfv! so depois disso alguem te irá ajudar... B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net
taviroquai Posted February 18, 2014 at 09:54 PM Report #545728 Posted February 18, 2014 at 09:54 PM (edited) Viva, Começa por separar marcação, estilo e comportamento... <html> <head> <!-- ESTILO --> <style> #xs { margin-left: 50px; padding: 0px; width: 80px; } #xs-target { display: none; } </style> </head> <body> <!-- bla bla bla --> <!-- MARCACAO --> <div class="pre-spoiler"> <input id="xs" value="Ver !" type="button"> </div> <div> <div id="xs-target" class="spoiler"> Aqui você coloca o texto que quer esconder e que só vai aparecer quando clicarem no botão. </div> </div> <!-- COMPORTAMENTO --> <script type="text/javascript"> var botao = document.getElementById('xs'); botao.addEventListener('click', function (evt) { var target = document.getElementById('xs-target'); if (target) { if (target.style.display != 'block') { target.style.display = 'block'; this.value = 'Ocultar'; } else { target.style.display = 'none'; this.value = 'Ver !'; } } }, false); </script> </body> </html> Edited February 18, 2014 at 09:57 PM by taviroquai 1 Report
Santana Oliveira Posted February 18, 2014 at 10:06 PM Author Report #545733 Posted February 18, 2014 at 10:06 PM (edited) Viva, Começa por separar marcação, estilo e comportamento... <html> <head> <!-- ESTILO --> <style> #xs { margin-left: 50px; padding: 0px; width: 80px; } #xs-target { display: none; } </style> </head> <body> <!-- bla bla bla --> <!-- MARCACAO --> <div class="pre-spoiler"> <input id="xs" value="Ver !" type="button"> </div> <div> <div id="xs-target" class="spoiler"> Aqui você coloca o texto que quer esconder e que só vai aparecer quando clicarem no botão. </div> </div> <!-- COMPORTAMENTO --> <script type="text/javascript"> var botao = document.getElementById('xs'); botao.addEventListener('click', function (evt) { var target = document.getElementById('xs-target'); if (target) { if (target.style.display != 'block') { target.style.display = 'block'; this.value = 'Ocultar'; } else { target.style.display = 'none'; this.value = 'Ver !'; } } }, false); </script> </body> </html> Obrigado se calhar era o que utilizador CRLF queria mas não percebi... Agora só falta clicar num botão e o botão com o texto minimizar (fechar) Edited February 18, 2014 at 10:08 PM by Santana Oliveira
taviroquai Posted February 18, 2014 at 10:13 PM Report #545735 Posted February 18, 2014 at 10:13 PM O código que coloquei funciona: faz um toggle ao element com ID xs-target. 1 Report
Santana Oliveira Posted February 18, 2014 at 10:20 PM Author Report #545739 Posted February 18, 2014 at 10:20 PM (edited) O código que coloquei funciona: faz um toggle ao element com ID xs-target. Importa-se de dizer com se faz isso? Ainda estou a aprender Javascript... Deste já agradeço a sua ajuda... 🙂 Edited February 18, 2014 at 10:20 PM by Santana Oliveira
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