Jump to content
php.lv forumi
  • 0

Show / Hide diw


goma smile

Question

function showdiv(name){
var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
   if (obj.style.display=="none"){	
       obj.style.display="";    
   }else{	 
       obj.style.display="none";
   }
}

 

Šī ir showdiv funckija ar ko uzpiežot uz kka paradas div lodzinš kur kkas ir iebombīts

Vai kāds lūdzu nevarētu palīdzēt izvedot tā, Tagad ir tā ir tā:

<a onClick="showdiv(\'div1\');" >Atveri div 1</a>
<a onClick="showdiv(\'div2\');" >Atveri div 2</a>

<div id="div1" style="display: none;">
1
</div>

<div id="div2" style="display: none;">
2
</div>

 

Kad uzpied uz 1 viņš atver 1 un, kad 2 tad atver paralēli arī 2, a es vēlos tā, lai kad uzpied uz 1 atverās 1 a, kad uzpied uz 2 aizverās 1 atverās 2.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Man nebija ko darit un vajadzeja izmegjinat vienu editoru ta ka plz kods ieksh jQuery. Ja velies, tad vari partranslet uz parastu JS.

 


<html>
<head>
	<title>Show/Hide Example</title>
	<style type="text/css">
	body {
		text-align:center;
	}
	.box {
		width:150px;
		height:150px;
		margin:20px auto;
		background-color:#ddd;
		color:#333;
		text-shadow:#eee;
		display:inline-block;
		font-weight:bold;
		border:1px #222 solid;
		cursor:pointer;
		display:none;
	}
	span {
		vertical-align:middle;
		line-height:150px;
		font-size:20pt;
	}
	</style>
</head>

<body>
	<a href="#" class="toggle-boxes" id="toggle-box-1">Show - 1</a> |
	<a href="#" class="toggle-boxes" id="toggle-box-2">Show - 2</a>

	<br />

	<div class="box" id="box-1">
		<span>Visible - 1</span>
	</div>

	<div class="box" id="box-2">
		<span>Visible - 2</span>
	</div>

	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
	<script type="text/javascript">
	$('.toggle-boxes').click(function() {
		var box_id = $(this).attr('id').split('-')[2];

		$('.box').hide();
		$('#box-' + box_id).show();

		return false;
	});
	</script>
</body>
</html>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...