网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 基于javascript的JSON格式页面展示美化
范文
    {"name": "monkey","age": "24","height": 164.0}
    如果想让以上json字符串在页面上展示的比较易读,即变成下面的style:
    "name": "monkey",
    "age": "24",
    "height": 164.0cm
    }
    本文介绍的方法基于javascript ,代码如下:
    <html>
    <head>/
    //style中是css代码
    <style type="text/css">
    body
    {
    white-space: pre;
    font-family: monospace;
    }
    </style>
    //script中是javascript代码
    <script>
    window.error_id_msgs = <%= error_id_msgs | raw %>;
    function myFunction() {
    document.body.innerHTML = "";
    document.body.appendChild(document.createTextNode(JSON.stringify(window.error_id_msgs, null, 4)));
    }
    </script>
    </head>
    <body onload="myFunction()"> //表示页面加载时调用myFunction()
    </body>
    </html>
    其中window.error_id_msgs是所要转换的json对象,css和myFunction结合可实现页面展示转换
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/21 22:02:44