粗糙的object打印日志用....
程序员文章站
2024-02-02 19:52:52
...
function logJquery(o){ var map = o;//document.getElementById("speed").value //{"key1": [4,2,5], //"key2": [33,55,44] // }; var str =toJSON(map); document.getElementById("speed").value = str; } function toJSON(value) { var type = $.type(value); switch(type) { case 'array' :return arrayToJSON(value); case 'object' :return objectToJSON(value); case 'string' :return "'"+value+"'"; default :return value; } } function arrayToJSON(o){ var la = function(value){ var list = []; for(var i in value){ list.push(toJSON(value[i])); } return list ; } return "["+la(o).join(",")+"]"; } function objectToJSON(o){ var lo= function (value){ var list = []; for(var i in value){ list.push(toJSON(i)+":"+toJSON(value[i])) } return list; } return "{"+lo(o).join(",")+"}"; }