52,797
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>测试AJAX</title>
<script type="text/javascript">
function testAJAX(id) {
var xmlhttp;
var pAnswer = document.getElementById(id).value;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject();
}
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readystate == 4 && xmlhttp.state == 200){
var testtest = xmlhttp.responseText;
if(pAnswer == testtest){
document.getElementById(id).style.backcolor = "red";
}else{
document.getElementById(id).style.backcolor = "yellow";
settimeout(1000);
document.getElementById(id).style.display = "none";
}
}
}
xmlhttp.open("POST","testPHP.php",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div>
<P>你说哪个答案正确?</P>
<P id="pa" name="pa" value="" onclick="testAJAX(this.id);">A、错误</P>
<P id="pb" name="pb" value="" onclick="testAJAX(this.id);">B、错误</P>
<P id="pc" name="pc" value="" onclick="testAJAX(this.id);">C、错误</P>
<P id="pd" name="pd" value="" onclick="testAJAX(this.id);">D、正确</P>
<P id="pe" name="pe" value="" onclick="testAJAX(this.id);">E、错误</P>
</div>
</body>
</html>
<?php
$answer = "D";
echo $answer;
?>