console.log是什么東西,其實(shí)就是一個打印js數(shù)組和對像的函數(shù)而已,就像是php的print_r,var_dump。console.log這個函數(shù)本身沒什么好說的,這篇博客告訴大家怎么去用這個函數(shù)。在說這個函數(shù)之前,我想大家用的最多查看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 開發(fā)工具查看js對像
console chrome
現(xiàn)在chrome開發(fā)者工具和firebug,我用的時候,一半對一半。chrome開發(fā)者工具,還有一個功能,firebug不具有.
控制臺可以運(yùn)行js,如果這個頁面是iframe的話,firebug只能運(yùn)行在父級上面,而chrome可以選擇里面的頁面執(zhí)行,如果下圖
chrome iframe console
三、firebug查看js對像
firebug console
希望本文所述對大家JavaScript程序設(shè)計有所幫助。
更多js console.log打印對像與數(shù)組用法詳解相關(guān)文章請關(guān)注PHP中文網(wǎng)!
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com