在JavaScript中使用console.log打印对像、数组等调试代码

js console.log 打印 对像 数组 详解


console.log是什么东西,其实就是一个打印js数组和对像的函数而已,就像是php的print_r,var_dump。console.log这个函数本身没什么好说的,这篇博客告诉大家怎么去用这个函数。在说这个函数之前,我想大家用的最多查看js输出,是alert吧,但是alert,只能弹string或者是int的

一,测试文件test.html

  1. <html xmlns="http://www.w3.org/1999/xhtml">  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  4. <title>console.log test</title>  
  5. </head>  
  6.   
  7. <script type="text/javascript">  
  8. var testobj =  
  9.     {  
  10.         'id': 1,  
  11.         'content': 'test',  
  12.         'firstname': function() {  
  13.             document.getElementById('firstname').value = "zhang";  
  14.         },  
  15.         'lastname': function() {  
  16.            document.getElementById('lastname').value = "ying";  
  17.         }  
  18.     };  
  19. <!-- 打印对像 -->  
  20.     console.log(testobj);  
  21. </script>  
  22.   
  23. <body>  
  24.   
  25.      <input type="text" id='firstname' name="firstname" value=''>  
  26.      <input type="text" id='lastname' name='lastname' value=''>  
  27.   
  28. </body>  
  29. </html>  

二,chrome 开发工具查看js对像


console chrome

console chrome

现在chrome开发者工具和firebug,我用的时候,一半对一半。chrome开发者工具,还有一个功能,firebug不具有.

控制台可以运行js,如果这个页面是iframe的话,firebug只能运行在父级上面,而chrome可以选择里面的页面执行,如果下图


chrome iframe console

chrome iframe console

三,firebug查看js对像


firebug console

firebug consol
e

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值