<?php header("Content-type: text/html; charset=utf-8"); $p13=$str['UserId']; //获取当前访问者唯一id:P13 $sql_num="select count(*)as num from yb_grade where p13='".$p13."'"; $rows_num=$db->db_query($sql_num); if($rows_num[0]["NUM"]==0){ $sql_exam="select * from yb_exam order by examid"; $rows_exam=$db->db_query($sql_exam); $str=""; if(!empty($rows_exam)) { foreach($rows_exam as $k=> $v) { $examid = $v['EXAMID']; $examname = $v['EXAMNAME']; $examname = iconv('GBK','UTF-8',$examname); $optiona = $v['OPTIONA']; $optiona = iconv('GBK','UTF-8',$optiona); $optionb = $v['OPTIONB']; $optionb = iconv('GBK','UTF-8',$optionb); $optionc = $v['OPTIONC']; $optionc = iconv('GBK','UTF-8',$optionc); $optiond = $v['OPTIOND']; $optiond = iconv('GBK','UTF-8',$optiond); $answer = $v['ANSWER']; $str.="<div> <div> ".$examid."、".$examname." </div> <div> <input type='radio'name='radio".$examid."' id='radio".$examid."A' value='A'><label for='radio".$examid."A'>A ".$optiona."</label><br> <input type='radio'name='radio".$examid."' id='radio".$examid."B' value='B'><label for='radio".$examid."B'>B ".$optionb."</label><br>"; if(!empty($optionc)){ $str.=" <input type='radio'name='radio".$examid."' id='radio".$examid."C' value='C'><label for='radio".$examid."C'>C ".$optionc."</label><br>"; } if(!empty($optiond)){ $str.=" <input type='radio'name='radio".$examid."' id='radio".$examid."D' value='D'><label for='radio".$examid."D'>D ".$optiond."</label><br>"; } $str.="</div> <div style='background:#f8f6f3;display:none' class='message' > <div style='color:red' class='result'>正确答案为:<span class='answer'>".$answer."</span> </div> </div> </div>"; } } }else{ echo "<script>alert('请勿重复参加');window.history.back(-1);</script>"; die; } ?> <html> <head> <title></title> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="no-cache"> <meta http-equiv="Expires" content="0"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="initial-scale=1, maximum-scale=1"> <link rel="shortcut icon" href="/favicon.ico"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <link href="../function/layer_mobile/need/layer.css" rel="stylesheet" type="text/css"> <script src="../function/js/jquery.js"></script> <script src="../function/layer_mobile/layer.js"></script> <script type="text/javascript"> var p13="<?php echo $p13;?>"; function tijiao(){ $("#tijiao").css("display","none"); $(".message").css("display",""); var grade=0; var checkInputs = $("input:checked") // 获取选中的input var answer=$(".answer").text(); var result=$(".result"); for(var i = 0;i<checkInputs.length;i++){ var v = checkInputs[i].value; // 计算 $(checkInputs[i]).next().css("color","#47cccc") if(v==answer[i]){ $(result[i]).append("<img src='./img/right.png'>"); grade=grade+5; }else{ $(result[i]).append("<img src='./img/error.png'>"); } } $.ajax({ type: "POST", async:true, url: "./save.php", cache:false, data:"grade="+grade+"&p13="+p13, dataType:"text", success:function(msg)//ajax成功 { if(msg!="101"){ console.log(msg); var array=msg.split(","); $("#grade").text(array[0]+"分"); $("#pm").text(array[1]+"名"); $("#num").text(array[2]+"人"); $("#information").css("display",""); $("input[type='radio']").attr("disabled",true); //回到顶端 scroll(0,0); }else{ alert("不好意思,出错啦"); } } }) } </script> </head> <body > <div style="height:50px;100%;text-align:center;font-size:25px;font-weight:bolder">考试试卷</div> <div id="information" style="height:350px;323px;background:transparent url(./img/grad.png) no-repeat scroll 0 0;margin:0 auto;text-align:center;font-size:20px;line-height:50px;display:none;"> <div style="height:50px;"></div> <div> <span>成绩:</span><span id="grade" style="color:red;font-size:25px;"></span> </div> <div> <span>排名:</span><span id="pm"></span> </div> <div> <span>满分:</span><span >100分</span> </div> <div > <span>人数:</span><span id="num"></span> </div> </div> <div style="margin-top:20px;line-height:40px;padding:5px;100%"> <form > <?php echo $str; ?> <div id="tijiao" style="text-align:center;margin-top:10px;" onclick=tijiao()><input type="button" value="提交" style="font-size:18px;background:#a0e1ff;color:white;80%;height:50px;"></div> </form> </div> </body> </html>