欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于javascript的JSON格式頁(yè)面展示美化方法

 更新時(shí)間:2014年07月02日 16:42:16   投稿:whsnow  
本文介紹的方法基于javascript,css和myFunction結(jié)合可實(shí)現(xiàn)頁(yè)面展示轉(zhuǎn)換,下面有個(gè)示例,大家可以參考下
{"name": "monkey","age": "24","height": 164.0}

如果想讓以上json字符串在頁(yè)面上展示的比較易讀,即變成下面的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()"> //表示頁(yè)面加載時(shí)調(diào)用myFunction() 
</body> 
</html>

其中window.error_id_msgs是所要轉(zhuǎn)換的json對(duì)象,css和myFunction結(jié)合可實(shí)現(xiàn)頁(yè)面展示轉(zhuǎn)換

相關(guān)文章

最新評(píng)論