我似乎无法弄清楚当我在第一个 div 上时如何简单地隐藏“prev”按钮,而在最后一个 div 上时如何隐藏“next”按钮。
希望有专业人士愿意帮助新手。这是我的代码:
<!DOCTYPE html>
<html>
<head>
<style>
div { width:40px; height:40px; margin:10px; float:left; border:2px blue solid; padding:2px; }
span { font-size:14px; }
p { clear:left; margin:10px; }
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div></div>
<div></div>
<div></div>
<div id="start"></div>
<div></div>
<p><button id="prev">Prev</button></p>
<p><button id="next">Next</button></p>
<script type="text/javascript">
var $curr = $("#start");
$curr.css("background", "#f99");
$("#prev").click(function () {
$curr = $curr.prev();
$("div").css("background", "");
$curr.css("background", "#f99");
});
var $curr = $("#start");
$curr.css("background", "#f99");
$("#next").click(function () {
$curr = $curr.next();
$("div").css("background", "");
$curr.css("background", "#f99");
});
</script>
</body>
</html>