这是我的管理考试,我正在尝试进行修改。考试一个接一个地隐藏另一个问题 如果答案是正确的,我按下其中一个答案,然后再转到下一个问题的背景 被压缩的问题如果是正确答案则变为绿色,如果是错误的答案则为红色。
我想要什么:当用户按下错误的答案时,我希望系统不仅要显示按下按钮的红色背景, 也使得正确答案的背景为绿色。向用户显示这种方式的正确答案是什么。如果我错过了代码,请告诉我。
PHP
$orderbyrand = "SELECT * FROM management
ORDER BY rand(), `answer` ASC LIMIT 2";
$rend_result=mysql_query($orderbyrand);
$k=1;
while($row_rand=mysql_fetch_array($rend_result)){
$answerarry[$k]= $row_rand['answer'];
$k++;}
$answerarry['0'] = $answerarry_shuffle['0'];
$answerarry['1'];
$answerarry['2'];
shuffle($answerarry);
if($answerarry_shuffle['0']==$answerarry[0])
{ $correcr_answer[0]=1; } else { $correcr_answer[0]=0; }
if($answerarry_shuffle['0']==$answerarry[1])
{ $correcr_answer[1]=1; } else { $correcr_answer[1]=0; }
if($answerarry_shuffle['0']==$answerarry[2])
{ $correcr_answer[2]=1; } else { $correcr_answer[2]=0; }
Javascript
function change_question(quest_num,optionvalue,ans_div_num){
var hidediv = 'question_'+optionvalue;
var add_optionvalue = (Number(optionvalue)+Number(1));
var showdiv = 'question_'+add_optionvalue;
var noofques = document.getElementById('noofques').value;
var totalno = (Number(noofques)+Number(1));
var totalcount = document.getElementById('noofques').value=totalno;
if(quest_num==1){
var correct_answer = document.getElementById('optvalue').value;
var optinoresult_add = (Number(correct_answer)+Number(1));
var addoptvalue = document.getElementById('optvalue').value=optinoresult_add;
document.getElementById('answerdiv_'+ans_div_num+'_'+optionvalue).style.background='#bbd387';
} else {
var correct_answer = document.getElementById('optvalue').value;
var optinoresult_add = (Number(correct_answer)+Number(0));
var addoptvalue = document.getElementById('optvalue').value=optinoresult_add;
if(ans_div_num!=0){
document.getElementById('answerdiv_'+ans_div_num+'_'+optionvalue).style.background='#dd5f5b'; }
}
}
HTML
<div class="row-fluid answer">
<div id="answerdiv_1_<?php echo $i; ?>" onClick="return change_question('<?php echo $correcr_answer[0]; ?>','<?php echo $i; ?>','1');" class="span12 show_cursor"><p><?php echo substr($answerarry[0],0,300);?></p></div>
</div>
<div class="row-fluid answer">
<div id="answerdiv_2_<?php echo $i; ?>" onClick="return change_question('<?php echo $correcr_answer[1]; ?>','<?php echo $i; ?>','2');" class="span12 show_cursor"><p><?php echo substr($answerarry[1],0,300);?></p> </div>
</div>
<div class="row-fluid answer">
<div id="answerdiv_3_<?php echo $i; ?>" onClick="return change_question('<?php echo $correcr_answer[2]; ?>','<?php echo $i; ?>','3');" class="span12 show_cursor"><p><?php echo substr($answerarry[2],0,300);?></p> </div>
</div>