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

基于javascript的JSON格式頁面展示美化方法

 更新時間:2014年07月02日 16:42:16   投稿:whsnow  
本文介紹的方法基于javascript,css和myFunction結合可實現(xiàn)頁面展示轉換,下面有個示例,大家可以參考下
{"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結合可實現(xiàn)頁面展示轉換

相關文章

最新評論