• 实现json的三个操作(训练JSON)


    1、实现JSON的对象的显示:

    jsonObj

    效果:

    2、实现JSON字符串数组的下拉列表显示:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>实现JSON</title>
        <script>
    
            function loadArray() {
               var cn = ["德国","英国","中国"];
               var cnselect = "<select>";
               for (var i = 0;i<cn.length;i++){
                   cnselect += "<option value='"+i+"'>"+cn[i]+"</option>";
               }
               cnselect += "</select>";
               document.getElementById("jsonArray").innerHTML = cnselect;
            }
    
        </script>
    </head>
    <body onload="loadArray()">
    
    <div id="jsonArray"></div>
    
    </body>
    </html>

    效果:

     3、实现JSON对象数组的表格显示:

    jsonObjArray
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>JSON的实现</title>
        <script>
            function loadObjArray() {
                var objs = [{"id":"1001","name":"admin","pwd":"000000"},{"id":"1002","name":"axe","pwd":"123456"},{"id":"1003","name":"gsl","pwd":"666666"}];
            var trs = "<tr><td>ID</td><td>姓名</td><td>密码</td></tr>";
            for (var i = 0;i<objs.length;i++){
                trs += "<tr><td>"+objs[i].id+"</td><td>"+objs[i].name+"</td><td>"+objs[i].pwd+"</td></tr>";
            }
            document.getElementById("jsonObjArray").innerHTML = trs;
            }
    
        </script>
    </head>
    <body onload="loadObjArray()">
    <table id="jsonObjArray"border="1"width="300px">
    
    </table>
    
    </body>
    </html>

    效果:

  • 相关阅读:
    zz java compare 接口
    moodle 迁移
    Excel 散点图和折线图的区别
    leetcode Two Sum
    jQuery 常用方法大全<2>
    利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法
    回车验证信息
    SQL 创建密码
    高效的分页
    MVC 怎么样设置起始页
  • 原文地址:https://www.cnblogs.com/bichen-01/p/11689303.html
Copyright © 2020-2023  润新知