Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   кнопка, 3 div'а и click (https://javascript.ru/forum/dom-window/34734-knopka-3-div%27-i-click.html)

eko24 16.01.2013 23:21

кнопка, 3 div'а и click
 
есть следующая html старница:
<div id="1"><button class="next">next</button></div>
<div id="2"><button class="next">next</button></div>
<div id="3">end</div>

к ним выполняться такой jquery код:
$(function() {
	$("div").hide();
	$("#1").show();
});

то есть все div'ы прячутся а первый показывается.
нужно что бы при нажатии кнопки текущий div прятался, а следующий открывался.

как это реализовать ?

ksa 17.01.2013 11:17

Цитата:

Сообщение от eko24
как это реализовать ?

Как вариант...

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="tmp.css" />
-->
<style type="text/css">
#container > div {
	display: none;
}
#container > .on {
	display: block;
}
</style>
<script type="text/javascript">
$(document).ready(function (){
	$('.next').click(function (){
		var o=$(this).parent('div');
		o.removeClass('on');
		o=o.next();
		o.addClass('on');
	});
});
</script>
</head>
<body>
<div id='container'>
	<div class='on'><button class="next">next 1</button></div>
	<div><button class="next">next 2</button></div>
	<div><button class="next">next 3</button></div>
	<div>end</div>
</div>
</body>
</html>

ksa 17.01.2013 11:20

Или так...

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="tmp.css" />
-->
<style type="text/css">
#container > div {
	display: none;
}
#container :first-child {
	display: block;
}
</style>
<script type="text/javascript">
$(document).ready(function (){
	$('.next').click(function (){
		$(this).parent('div').hide().next().show();
	});
});
</script>
</head>
<body>
<div id='container'>
	<div><button class="next">next 1</button></div>
	<div><button class="next">next 2</button></div>
	<div><button class="next">next 3</button></div>
	<div>end</div>
</div>
</body>
</html>

eko24 17.01.2013 17:40

Большое спасибо !


Часовой пояс GMT +3, время: 05:25.