【发布时间】:2015-07-31 13:52:48
【问题描述】:
所以我试图隐藏/显示 3 个不同的 div。我想跟踪哪个正在显示,以便我可以拥有下一个和后退功能。这是我目前所拥有的:
<!DOCTYPE html>
<html>
<head>
<title><cfoutput>#getgame.name# - Introduction</cfoutput></title>
<link rel="stylesheet" type="text/css" href="css/sigmasim.css">
<link rel="stylesheet" href="css/fonts.css" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".content2").hide();
$(".content3").hide();
});
var i = 0;
var j = 0;
function Back(){
$("#target1 a").click(function(){
if (i != 0){
j = i - 1;
i = i - 1;
if (j == 0){
$(".content").show();
$(".content2").hide();
$(".content3").hide();
} else if (j == 1){
$(".content").hide();
$(".content2").show();
$(".content3").hide();
} else {
$(".content").show();
$(".content2").hide();
$(".content2").hide();
}
}
});
}
function Next(){
$("#target2 a").click(function(){
if (j != 4){
j = i + 1;
i = i + 1;
if (j == 1){
$(".content").hide();
$(".content2").show();
$(".content3").hide();
} else if (j == 2){
$(".content").hide();
$(".content2").show();
$(".content3").hide();
} else if (j == 3){
$(".content").hide();
$(".content2").hide();
$(".content2").show();
} else {
$(".content").show();
$(".content2").hide();
$(".content2").hide();
}
}
});
}
</script>
</head>
<body>
<div class="content">
<p> hi </p>
</div>
<div class="content2">
<p> hi2 </p>
</div>
<div class="content3">
<p> hi3 </p>
</div>
<div style="display: inline-block; width: 50%; text-align: left; font-size: 24px;" id="target1">
<a href="#" onclick="javascript:Back();">Back</a>
</div><div style="display: inline-block; width: 50%; text-align: right; font-size: 24px;" id="target2">
<a href="#" onclick="javascript:Next();">Next</a>
</div>
</body>
</html>
单击下一步时,我在 i 和 j 都添加了 console.log 后注意到的第一件事是它不会在第一次单击时进行评估。如果再次单击下一步,它将通过该功能两次。即使对于后退功能,它也会继续这样做。
我想对三个“页面”进行索引,如果您在第一页,则不提供返回选项,并且对于超过第三页也是如此。
谢谢,-Z
【问题讨论】: