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
希望本文所述對大家JavaScript程序設計有所幫助。
更多js console.log打印對像與數組用法詳解相關文章請關注PHP中文網!
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com