JS格式化JSON串显示在表格中

JS代码如下,这里用了jq的语法:

<script type="text/javascript">
$(function(){
    var text = $("#show_json").html();
    var result = JSON.stringify(JSON.parse(text), null, 4);
    $("#show_json").html("<pre>"+result+"</pre>");
});
</script>

html部分代码:

<table>
            <tr>
              <td>json: </td>
              <td><p id="show_json">{"aaa":"111", "bbb":"222", "ccc":"333"}<p></td>
            </tr>
</table>

看下效果图:

猜你喜欢

转载自www.cnblogs.com/jimmyshan-study/p/11229373.html