解决方案 »
- 急~~~~在线等候~~~ php批量删除问题,请求帮助,多选的时候为什么只能删1条信息哦
- PHP本地调试成功,上传到服务器之后无法成功获取?
- PHP里如何获取函数的调用者名称
- 判断某字符在某字符里面
- PHP邮件函数mb_send_mail(),错误警告
- php IDE 编写软件?
- mod_php4-4.0.1-pl2.zip 这个文件到那下啊?
- http://www.fjscw.com/test/text.php这将那幅LOGO图片(.gif)文件,插到那幅图片上,怎么图片质量变低了?
- 请问php中怎样往非关系型数据库中加入一条记录!??
- date()型的数据如何insert数据库(postgresql),紧急求助!
- iis和php的整合后出现这样的问题
- 如何将数据库查询的记录集 赋值给表格
$answer = $items[$seq]['anwser'];
说起思路 我自己是用用php里数组 html中传递value判断
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<title> question and answer </title>
</head> <body>
<p id="question"></p>
<p>answer:<input type="text" id="answer"></p>
<p><input type="submit" value="submit" id="smb"></p>
<input type="hidden" id="index"> <script type="text/javascript">
$(document).ready(function(){
$.getJSON("a.php?type=get", function(data){
$('#question').html(data['question']);
$('#index').val(data['index']);
});
})
var lock = 0;
$('#smb').click(function(){
if($.trim($('#answer').val())==''){
alert('please input answer');
return false;
}
lock = 1;
$.getJSON("a.php?type=check&answer=" + encodeURIComponent($('#answer').val()) + "&index=" + encodeURIComponent($('#index').val()), function(data){
if(data.ret==true){
alert('answer is correct');
}else{
alert('answer is incorrect');
}
lock =0;
});
});
</script>
</body>
</html>a.php<?php
$type = isset($_GET['type'])? $_GET['type'] : '';$question = array(
array('一年有多少天','365天'),
array('一天有几个小时?','24小时'),
array('1+1=?','2'),
array('2+2=?','4'),
array('3+3=?','6'),
array('4+4=?','8'),
array('5+5=?','10'),
array('6+6=?','12'),
array('7+7=?','14'),
array('8+8=?','16'),
array('9+9=?','18'),
);if($type=='get'){
$index = mt_rand(0, count($question)-1);
echo json_encode(array('question'=>$question[$index][0],'index'=>$index));
}elseif($type=='check'){
$answer = isset($_GET['answer'])? $_GET['answer'] : '';
$index = isset($_GET['index'])? $_GET['index'] : '-1'; $result = false; if(isset($question[$index])){
if($question[$index][1]==$answer){
$result = true;
}
} echo json_encode(array('ret'=>$result));
}
?>