我的主页
<html>
<head>
<!--<link href="css/style.css" type="text/css" rel="stylesheet"> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script src="jquery/myscript.js"></script>
</head>
<body>
<?php
$dbconnect=mysqli_connect('localhost','root','','quiz')or die("Error Connecting to database");
$query="select * from question_answer ";
$result=mysqli_query($dbconnect,$query);
?>
<form method="get" action="">
<div id="container">
<?php
while($rows=mysqli_fetch_array($result))
{
echo '<div class="QA">';
echo '<h1>'.$rows['question'].'</h1>'.'<br/>';
echo '<input type="radio" class="check" name="'.$rows['id'].'" value="A">'.$rows['option1'].'</input>';
echo '<input type="radio" class="check" name="'.$rows['id'].'" value="B">'.$rows['option2'].'</input>';
echo '<input type="radio" class="check" name="'.$rows['id'].'" value="C">'.$rows['option3'].'</input>';
echo '<input type="radio" class="check" name="'.$rows['id'].'" value="D">'.$rows['option4'].'</input>';
echo '<br/>';
echo '<div class="report"></div>';
echo'</div>';
}
?>
</div>
</form>
</body>
</html>
这是我的脚本,当我提醒从 php 收到的数据它的工作时,我有 ajax 传递值和 php 返回数据,但是在下面的行之后我有我的 jquery 来显示结果并且 slideUP 不工作
$(document).ready(function(){
var clickedvalue,qid;
$("input:radio").change(function(){
clickedvalue=$(this).val();
qid=$(this).attr('name');
$.get('checkanswer.php',{'clickedvalue':clickedvalue,'qid':qid},function(data){
$(this).parent("div.QA").find(".report").html(data);
$(this).slideUp();
});
});
});
这是php文件
<?php
$questionid=$_GET['qid'];
$answer=$_GET['clickedvalue'];
$dbconnect=mysqli_connect('localhost','root','','quiz')or die("Error Connecting to database");
$query="select answer from question_answer where id=$questionid";
$result=mysqli_query($dbconnect,$query);
while($rows=mysqli_fetch_array($result))
{
$dbanswer=$rows['answer'];
}
if($dbanswer==$answer)
{
echo "Correct Answer";
}
else{
echo "Incorrect Answer";
}
?>