如何使用jQuery和json响应填写文本字段和复选框?

时间:2016-10-18 16:01:09

标签: jquery json

这是我到目前为止的代码。

   <html>
   <head>
      <title>jQuery</title>
      <script type = "text/javascript" src = "js/jquery-3.1.1.min.js"></script>
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {
            $("#driver").click(function(event){
                var name = $("#name").val();
                $("#stage").load('result.cfm', {"name":name} );
                //$("#test").val(name);     
            });
         });
      </script>
   </head>
   <body>
      <p>Enter your name and click on the button:</p>
      <input type = "input" id = "name" size = "40" /><br />
      <div id = "stage" style = "background-color:ccc;">
         STAGE
      </div>
        Results
        <input type = "button" id = "driver" value = "Show Result" />
        <br><br><br>
        Name:
        <input type = "input" id = "fullname" size = "40" /><br />
        Age:
        <input type = "input" id = "age" size = "6" /><br />
        Sex:<br>
        <input type="checkbox" value="m"> Male <br>
        <input type="checkbox" value="f"> female <br>
   </body>
</html>

<!---
Result.cfm example returned.

{
"name": "Zara Ali",
"age" : "67",
"sex": "female"
}

---&GT;

0 个答案:

没有答案