一段显示对象所有属性和方法的代码,方便调试用

本文介绍了一个实用的JavaScript函数vardump,它可以将任意对象的信息以HTML格式展示在一个弹窗中,便于开发者快速查看对象的属性名、类型及具体值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

var dump = function(obj){
var a = "";
for(var i in obj){
a += "<div style='line-heigth:20px;border-bottom:1px dashed #DDDDDD;margin-bottom:10px;'>名字:[<span style='color:red'>"+i+"</span>] 类型: [<span style='color:green'>"+typeof(obj[i])+"</span>] 值:<br /><textarea style='width:630px;height:90px;'>"+obj[i] + "</textarea></div><br />";
}

var win = new Ext.Window({
title: "Dom查看器",
width: 700,
height: 450,
modal: false,
closeAction: "close",
resizable: true,
maximizable: true,
autoScroll: true,
items: [
{
xtype: "panel",
border: false,
width: 640,
html: "<pre>"+a+"</pre>"
}
],
buttons: [
{
text: CNOA.lang.btnClose,
bodyStyle: "padding:10px;",
iconCls: 'icon-dialog-cancel',
handler: function(){
win.close();
}
}
]
}).show();
}


使用方法:

dump(object);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值