我创建了一个网页,div
里面有一些大的 s。
我在那个页面上有一个按钮。单击该按钮时,我希望当前div
更改并显示下一个div
。
我已经写了一些代码,但不幸的是它不起作用:(
HTML:
<div class="tutorial">
<p class="heading">Tell us about yourself</p>
<div class="body">
<table>
<tr>
<td>
<label for="full_name">What's your full name?</label>
</td>
</tr>
<tr>
<td>
<input type="text" name="full_name" id="full_name" placeholder="Full Name" />
</td>
</tr>
<tr>
<td>
<br/>
</td>
</tr>
<tr>
<td>
<label for="about">Describe yourself:</label>
</td>
</tr>
<tr>
<td>
<textarea id="about" name="about" rows="5" cols="40" placeholder="Share you hobbies, interests and more about yourself"></textarea>
</td>
</tr>
<tr>
<td width="900px" height="60px"></td>
<td>
<button id="next" class="btn">Next</button>
</td>
</tr>
</table>
</div>
</div>
<div class="tutorial hidden">
<p class="heading">Tell us about yourself!</p>
<div class="body">Body</div>
</div>
<div class="tutorial hidden">
<p class="heading">Tell us about yourself!</p>
<div class="body">Body</div>
</div>
<div class="tutorial hidden">
<p class="heading">Tell us about yourself!</p>
<div class="body">Body</div>
</div>
<div class="tutorial hidden">
<p class="heading">Tell us about yourself!</p>
<div class="body">Body</div>
</div>
JS:
$(function () {
var tutorials = $("div.tutorial");
var idNumber = 1;
tutorials.each(function () {
$(this).attr("id", idNumber);
idNumber++;
});
var nextButton = $("#next");
$(nextButton).on('click', function () {
var currentTutorial = $("div.tutorial").not(".hidden");
var currentTutorialId = currentTutorial.prop("id");
currentTutorial.addClass("hidden");
var nextTutorialId = currentTutorialId++;
var nextDiv = null;
if ($("div.tutorial").is("#" + nextTutorialId)) {
var nextDiv = $("div.tutorial");
}
nextDiv.removeClass("hidden");
});
});
删除 CSS 以缩短问题的长度。:)
我想要什么: 我希望下一个按钮隐藏当前 div 并在它之后显示下一个 div。
我做了什么:
var currentTutorial = $("div.tutorial").not(".hidden");
var currentTutorialId = currentTutorial.prop("id");
currentTutorial.addClass("hidden");
var nextTutorialId = currentTutorialId++;
var nextDiv = null;
if ($("div.tutorial").is("#" + nextTutorialId)) {
var nextDiv = $("div.tutorial");
}
nextDiv.removeClass("hidden");