手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >基于javascript的JSON格式页面展示美化方法
基于javascript的JSON格式页面展示美化方法
摘要:{"name":"monkey","age":"24","height":164.0}如果想让以上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结合可实现页面展示转换

【基于javascript的JSON格式页面展示美化方法】相关文章:

javascript常用方法总结

javascript消除window.close()的提示窗口

在JavaScript中使用NaN值的方法

javascript动态设置样式style实例分析

javascript常用的方法分享

javascript动态创建链接的方法

javascript无刷新评论实现方法

在JavaScript中使用JSON数据

javascript中this的四种用法

javascript操作ul中li的方法

精品推荐
分类导航