我之前在調試代碼的時候,跟砸js代碼執行情況,一般都是通過在代碼塊中使用alert的方式查看js代碼的執行情況,今天也是看到有朋友使用console.log函數打印輸出函數,變量,對象,下邊就console.log的使用情況進行記錄,具體的語法是:
console.log("值為:",fn);
console.log()能夠輸出變量,函數,數組,對象等等
<html> <head> <title>this關鍵字_函數調用</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head> <body> <input type="text" id="test1" name="firstname" value="" /> <input type="text" id='lastname' name='lastname' value=''> </body> <script type="text/javascript"> var testobj = { 'id': 1, 'content': 'test', 'firstname': function() { var EleFirst= document.getElementById('test1'); //document.getElementById('firstname').value = "zhang"; //document.getElementById("test1").value = this.content; //document.getElementById("test1").setAttribute("value","zhang"); //this.content = val; EleFirst.setAttribute("value",this.content); console.log("對象的值為:",test1);//對象的值為:<input type="text" id="test1" name="firstname" value="" /> }, 'lastname': function() { document.getElementById('lastname').value = "ying"; } }; console.log(testobj);/** 打印對像**/ testobj.firstname(); testobj.lastname(); </script> </html>