我是一个有用的助手,可以将文本翻译成中文。
我有一个简单的页面,采用问题/答案布局。基本上,当用户点击他选择的答案时,当前问题会被隐藏,然后从隐藏的问题div中获取下一个问题,并显示出来,以此类推。没有包含Ajax。纯HTML和Jquery。
我的HTML代码:
问题描述:
第一次点击:当我第一次单击上面显示的
第二(和n次单击-第三次,第四次等)单击仅部分执行上述脚本。在Chrome调试控制台中没有显示任何错误。在这里,我将分解部分工作和不工作的脚本。
不工作的部分:
工作(至少看起来是这样,因为下一个问题显示正常):
这些例子导致了同样的问题。 提前感谢任何帮助。
我有一个简单的页面,采用问题/答案布局。基本上,当用户点击他选择的答案时,当前问题会被隐藏,然后从隐藏的问题div中获取下一个问题,并显示出来,以此类推。没有包含Ajax。纯HTML和Jquery。
我的HTML代码:
<div class="visible_questions">
<div id="question_block_74">
<h1> Question is ? </h1>
<label>
<div class="question-take">
<input type="radio" class="practise_answer_radio_btn" name="74" value="205">
1st answer
</div>
</label>
<label>
<div class="question-take">
<input type="radio" class="practise_answer_radio_btn" name="74" value="205">
2nd answer
</div>
</label>
</div>
</div>
<div class="hiden_questions" style="display:none;">
<div id="question_block_75" class="blocks_f">
<div class="question-take element">
<p> 2nd question </p>
</div>
<label>
<div class="question-take">
<input type="radio" class="practise_answer_radio_btn" name="75" value="207">
1st answer for 2nd question
</div>
</label>
<br>
<label>
<div class="question-take">
<input type="radio" class="practise_answer_radio_btn" name="75" value="208">
2nd answer for 2nd question .
</div>
</label>
</div>
<div id="question_block_76" class="blocks_f">
==//==
The same type of structure here
</div>
</div>
我的脚本:
$(".practise_answer_radio_btn").change(function(){
console.log("message just for testing");
var name = $(this).attr('name');
$("#question_block_" + name).hide();
var div_elements = $(".hiden_questions .blocks_f").length;
$(".hiden_questions .blocks_f:first-child").appendTo(".visible_questions");
if (div_elements == 0){
alert("End of the questions!");
}
});
问题描述:
第一次点击:当我第一次单击上面显示的
.practise_answer_radio_btn
按钮时,执行脚本100%而没有任何错误。因此,第一个问题被隐藏,并从 .hiden_questions
div中将新问题附加到 .visible_questions
div中。第二(和n次单击-第三次,第四次等)单击仅部分执行上述脚本。在Chrome调试控制台中没有显示任何错误。在这里,我将分解部分工作和不工作的脚本。
不工作的部分:
console.log("message just for testing");
if (div_elements == 0){ // when div_elements == 0 then this code doesn't execute
alert("End of the questions!");
}
工作(至少看起来是这样,因为下一个问题显示正常):
var name = $(this).attr('name');
$("#question_block_" + name).hide();
var div_elements = $(".hiden_questions .blocks_f").length;
$(".hiden_questions .blocks_f:first-child").appendTo(".visible_questions");
我尝试过的:
$(document).on('change','.practise_answer_radio_btn',function(){
$("body").on('change','.practise_answer_radio_btn',function(){
$(".practise_answer_radio_btn").change(function(){
这些例子导致了同样的问题。 提前感谢任何帮助。