1
因爲在網絡應用程序中顯示所有問題看起來不太好,所以我想在一個頁面中提出一個問題。 但是,當我鍵入這些代碼時,「上一個」按鈕不起作用。 當我點擊上一個按鈕後,「下一個」按鈕不會在之後。 但是,我可以做得很好,並顯示頁碼? 非常感謝。如何在每個頁面上顯示一個表單元素?
這是我的代碼:
<script>
$(document).ready(function(){
var totalQuestions = $('.questions').size();
var currentQuestion = 0;
$questions = $('.questions');
$questions.hide();
$($questions.get(currentQuestion)).fadeIn();
$('#next').click(function(){
$($questions.get(currentQuestion)).fadeOut(function(){
currentQuestion = currentQuestion + 1;
$($questions.get(currentQuestion)).fadeIn();
});
if(currentQuestion==(totalQuestions-2)){
$('#next').attr("class","ui-btn ui-shadow ui-corner-all ui-icon-arrow-r ui-btn-icon-right ui-state-disabled ui-btn-inline");
}else{
$('#next').attr("class","ui-btn ui-shadow ui-corner-all ui-icon-arrow-r ui-btn-icon-right ui-btn-inline");
}
});
$('#prev').click(function(){
$($questions.get(currentQuestion)).fadeOut(function(){
currentQuestion = currentQuestion - 1;
$($questions.get(currentQuestion)).fadeIn();
});
if(currentQuestion==1||currentQuestion==0){
$('#prev').attr("class","ui-btn ui-shadow ui-corner-all ui-icon-arrow-l ui-btn-icon-left ui-state-disabled ui-btn-inline");
}
});
});
$(document).ready(function() {
$('div.questions').find('input:radio').prop('checked', false);
});
</script>
這些都是組成部分:
<form action="result.php?id=<?php echo $course_id;?>&cm_id=<?php echo $cm_id; ?>" method="post">
<?php
$getAssessmentSQL="SELECT * FROM assessment WHERE course_material_id=$cm_id order by rand()";
$ResultAssessment=mysql_query($getAssessmentSQL);
// display a series of random images - PHP form solution
// (c) 2004 David Pankhurst - use freely, but please leave in my credit
$j=array(1,2,3,4);
srand(time());
shuffle($j);
while($getAssessment=mysql_fetch_array($ResultAssessment)){
//if multiple choice, then this method
echo "<div class='questions'>";
echo "<legend>".$getAssessment['question']."</legend>";
echo "<div class='options'>";
echo "<fieldset data-role='controlgroup'>";
for($i=0;$i<4;$i++){
echo "<label for='".$getAssessment['assessment_id'].$j[$i]."'>".$getAssessment['choice'.$j[$i]]."</label>
<input class='option' type='radio' name='".$getAssessment['assessment_id']."' id='".$getAssessment['assessment_id'].$j[$i]."' value='".$j[$i]."'>
";
}
echo "</fieldset>";
echo "</div>";
echo "</div>";
}
?>
<a name="ClickPrev" class="ui-btn ui-shadow ui-corner-all ui-icon-arrow-l ui-btn-icon-left ui-btn-inline" id="prev">Previous</a>
<a name="ClickNext" class="ui-btn ui-shadow ui-corner-all ui-icon-arrow-r ui-btn-icon-right ui-btn-inline" id="next">Next</a>
<button type="submit" name="submit" value="submit" data-theme="b">Submit</button>
</form>
我只需要複製之間的代碼&? – 2015-03-25 10:00:31