首页  >  文章  >  web前端  >  js console.log打印对像与数组用法详解

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

高洛峰
高洛峰原创
2017-02-03 14:42:051164浏览

本文实例讲述了js console.log打印对像与数组用法。分享给大家供大家参考,具体如下:

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

一、测试文件test.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>console.log test</title>
</head>
<script type="text/javascript">
var testobj =
  {
    &#39;id&#39;: 1,
    &#39;content&#39;: &#39;test&#39;,
    &#39;firstname&#39;: function() {
      document.getElementById(&#39;firstname&#39;).value = "zhang";
    },
    &#39;lastname&#39;: function() {
      document.getElementById(&#39;lastname&#39;).value = "ying";
    }
  };
<!-- 打印对像 -->
  console.log(testobj);
</script>
<body>
   <input type="text" id=&#39;firstname&#39; name="firstname" value=&#39;&#39;>
   <input type="text" id=&#39;lastname&#39; name=&#39;lastname&#39; value=&#39;&#39;>
</body>
</html>

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

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

console chrome

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

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

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

chrome iframe console

三、firebug查看js对像

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

firebug console

希望本文所述对大家JavaScript程序设计有所帮助。

更多js console.log打印对像与数组用法详解相关文章请关注PHP中文网!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn