js console.log列印對像與數組用法詳解,jsconsole.log

來源:互聯網
上載者:User

js console.log列印對像與數組用法詳解,jsconsole.log

本文執行個體講述了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 =  {    'id': 1,    'content': 'test',    'firstname': function() {      document.getElementById('firstname').value = "zhang";    },    'lastname': function() {      document.getElementById('lastname').value = "ying";    }  };<!-- 列印對像 -->  console.log(testobj);</script><body>   <input type="text" id='firstname' name="firstname" value=''>   <input type="text" id='lastname' name='lastname' value=''></body></html>

二、chrome 開發工具查看js對像

console chrome

現在chrome開發人員工具和firebug,我用的時候,一半對一半。chrome開發人員工具,還有一個功能,firebug不具有.

控制台可以運行js,如果這個頁面是iframe的話,firebug只能運行在父級上面,而chrome可以選擇裡面的頁面執行,如果

chrome iframe console

三、firebug查看js對像

firebug console

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.