Jump to content

Abrir uma DIV


l00ker
 Share

Recommended Posts

Não me funciona sempre este código, já o analisei e não encontro nenhum erro

<html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<style type= "text/css ">
div{
border: solid 2px;
width: 500px;
height: 300px;
}
</style>

<script>
function mostrar_abas(obj) {

 document.getElementById('div_aba1').style.display="none";
  document.getElementById('div_aba2').style.display="none";
  document.getElementById('div_aba3').style.display="none";

  switch (obj.id) {
  case 'mostra_aba1':
  document.getElementById('div_aba1').style.display="block";
  break
  case 'mostra_aba2':
  document.getElementById('div_aba2').style.display="block";
  break
  case 'mostra_aba3':
  document.getElementById('div_aba3').style.display="block";
  break
  }
}

</script>

<li><a style="cursor: pointer; cursor: hand;" onclick="mostrar_abas(this);" id="mostra_aba1" >aba1</a></li>

<li><a style="cursor: pointer; cursor: hand;" onclick="mostrar_abas(this);" id="mostra_aba2" >aba2</a></li>

<li><a style="cursor: pointer; cursor: hand;" onclick="mostrar_abas(this);" id="mostra_aba3" >aba3</a></li>

<p></p>
<!-- abas -->
<div id="div_aba1" style="display:none;">
Conteúdo da aba 1
</div>
<div id="div_aba2" style="display:none;">
Conteúdo da aba 2
</div>
<div id="div_aba3" style="display:none;">
Conteúdo da aba 3
</div>
</html>
Edited by apocsantos
geshi
Link to comment
Share on other sites

Pode usar jQuery

<script src="http://code.jquery.com/jquery-latest.min.js"></script>

<script>
$(document).ready(function() {

$('.l').click(function(){
$('.d').hide();
$('#'+$(this).text()).show();
});

});
</script>

<style>
.d{display:none;}
</style>

<ul>
<li><a href="#" class="l">1</a></li>
<li><a href="#" class="l">2</a></li>
<li><a href="#" class="l">3</a></li>
</ul>

<div id="1" class="d">1</div>
<div id="2" class="d">2</div>
<div id="3" class="d">3</div>
Edited by apocsantos
geshi
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.