模仿php的print_r函数打印json数据
这是一个javascript模仿php的print_r函数打印json数据的公共函数,在http://www.36ria.com/2196上找的,方便测试。
(function($){ $.fn.print_r = function(json){ return $(this).each(function(e){ $(this).html(_print_r(json)); }) } function _print_r(theObj) { var retStr = ''; if (typeof theObj == 'object') { retStr += '<div style="font-size:12px;">'; for (var p in theObj) { if (typeof theObj[p] == 'object') { retStr += '<div><b>['+p+'] => ' + typeof(theObj) + '</b></div>'; retStr += '<div style="padding-left:25px;">' + _print_r(theObj[p]) + '</div>'; } else { retStr += '<div>['+p+'] => <b>' + theObj[p] + '</b></div>'; } } retStr += '</div>'; } return retStr; } $.print_r = function(json){ return _print_r(json); } })(jQuery);
调用方法:
jQuery("#选取一个div的ID").print_r(deptList);
相关推荐
weialemon 2020-05-05
doupoo 2020-05-04
Nicolase 2019-12-03
Lightmarec 2019-09-02
dmxtdxwi 2019-07-01
superhosts 2019-06-27
会写code的凳子哥 2012-06-23
WFMoonlight 2019-05-27
wqzbxh 2019-01-02
xiaohongyangOK 2018-11-10
azhedashuaibi 2019-01-02
lbcmail 2016-07-22
itkissit 2009-11-16
虚拟主机 2013-11-12
iamlazyphper 2019-04-11
PHP100 2019-03-28
PHP100 2019-03-28
PHP100 2019-03-28
PHP100 2019-03-28