本帖最后由 amhoho 于 2014-04-03 16:57:15 编辑

解决方案 »

  1.   

    代码不完整,仅给你点思路。剩下的自己做吧$user_answer = $_GET['user_answer'];$items = [['question' => '一年有多少天?', 'anwser' => '365'], ['question' => '一天有几个小时?', 'anwser' => '24']];$seq = rand(0, count($items)-1);$question = $items[$seq]['question'];
    $answer = $items[$seq]['anwser'];
      

  2.   

    这不是招人的面试题吗?我也搞不来  所以来请教学习 这和抄有关系?和我的饭碗又有什么关系?
    说起思路 我自己是用用php里数组 html中传递value判断
      

  3.   

    a.html<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <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));
    }
    ?>
      

  4.   

    @fdipzone 不错 我的思路差不多也是这样写的 嘿 要是我这的 来当同事吧 哈哈哈