检查 div 是否是最后一个并显示按钮
嘿伙计们。我有一个测验脚本,在不同的 div 中有问题,它们一个接一个地出现,我希望当最后一个 div 淡出时,它会显示提交按钮而不是下一个问题按钮。
这是我的js。
$('#questions').ready(function(){
for (i = 1; i < 100; i++) {
if ($('#question' + i).length > 0) {
$('#question' + i).hide();
} else {
break;
}
}
});
function transition(question_id) {
$('#question' + question_id).fadeOut('fast',function() {
question_id++;
if ($('#question' + question_id).length > 0) {
$('#question' + question_id).fadeIn('fast');
} else {
$('#test').submit();
} return false;
});
}
这是我的 html :
<div class="questions">
<div id="question0" class="question">
<span class="qutitle">asdg asdg</span> <br />
<FIELDSET>
<br /> <input id="q_0" type="radio" name="q_0" value="0"> sdgas <br />
<br /> <input id="q_0" type="radio" name="q_0" value="2">dgasdg <br />
<br /> <input id="q_0" type="radio" name="q_0" value="1">dgas <br />
</FIELDSET><input type="button" onclick="javascript: transition(0);" value="">
</div>
<div id="question1" class="question"><span class="qutitle">asdgasd</span> <br />
<FIELDSET>
<br /> <input id="q_1" type="radio" name="q_1" value="0">gasdg <br />
<br /> <input id="q_1" type="radio" name="q_1" value="2">asdgasdg <br />
<br /> <input id="q_1" type="radio" name="q_1" value="1">sdgasdg <br />
</FIELDSET><input type="button" onclick="javascript: transition(1);" value="">
</div>
<div id="question2" class="question"><span class="qutitle">sgasdgasd</span> <br />
<FIELDSET>
<br /> <input id="q_2" type="radio" name="q_2" value="1">asdgsad <br />
<br /> <input id="q_2" type="radio" name="q_2" value="2">gasdg <br />
<br /> <input id="q_2" type="radio" name="q_2" value="0">gasdg <br />
</FIELDSET><input type="button" onclick="javascript: transition(2);" value=""></div>
感谢任何形式的帮助。
谢谢。
Hey guys. I have a quiz script, that has questions in different divs, they come one after another, and I want that when the last div fadesIn it would show submit button instead of a next question button.
Here's my js.
$('#questions').ready(function(){
for (i = 1; i < 100; i++) {
if ($('#question' + i).length > 0) {
$('#question' + i).hide();
} else {
break;
}
}
});
function transition(question_id) {
$('#question' + question_id).fadeOut('fast',function() {
question_id++;
if ($('#question' + question_id).length > 0) {
$('#question' + question_id).fadeIn('fast');
} else {
$('#test').submit();
} return false;
});
}
Here's my html :
<div class="questions">
<div id="question0" class="question">
<span class="qutitle">asdg asdg</span> <br />
<FIELDSET>
<br /> <input id="q_0" type="radio" name="q_0" value="0"> sdgas <br />
<br /> <input id="q_0" type="radio" name="q_0" value="2">dgasdg <br />
<br /> <input id="q_0" type="radio" name="q_0" value="1">dgas <br />
</FIELDSET><input type="button" onclick="javascript: transition(0);" value="">
</div>
<div id="question1" class="question"><span class="qutitle">asdgasd</span> <br />
<FIELDSET>
<br /> <input id="q_1" type="radio" name="q_1" value="0">gasdg <br />
<br /> <input id="q_1" type="radio" name="q_1" value="2">asdgasdg <br />
<br /> <input id="q_1" type="radio" name="q_1" value="1">sdgasdg <br />
</FIELDSET><input type="button" onclick="javascript: transition(1);" value="">
</div>
<div id="question2" class="question"><span class="qutitle">sgasdgasd</span> <br />
<FIELDSET>
<br /> <input id="q_2" type="radio" name="q_2" value="1">asdgsad <br />
<br /> <input id="q_2" type="radio" name="q_2" value="2">gasdg <br />
<br /> <input id="q_2" type="radio" name="q_2" value="0">gasdg <br />
</FIELDSET><input type="button" onclick="javascript: transition(2);" value=""></div>
Any kind of help is appreciated.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
然后我想你可以这样做:
另外,在一开始,你可以只做
$('.questions').hide()
,而不是 for 循环。Then I guess you could do something like:
Also, in the beginning, you could just do
$('.questions').hide()
, instead of the for loop.$('div[id *= "question"]:last')
将获取 id 上带有“question”的最后一个 div。编辑:
要显示按钮,您可以这样做:
$('div[id *= "question"]:last')
will get the last div with "question" on the id.Edit:
To show the button, you can do this: