кнопка, 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 прятался, а следующий открывался. как это реализовать ? |
Цитата:
<!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>
|
Или так...
<!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>
|
Большое спасибо !
|
| Часовой пояс GMT +3, время: 14:37. |