今天看教學視頻學到了一個firebug的調試技巧,以前在網上也看到過,但就是不會用,現在我給大家弄一個圖文並茂的顯示
凡事動手很重要,通過例子學習較容易理解,先上代碼
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> firebug小技巧 </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
function showLog(message){
console.log(message);
console.info(message);
console.warn(message);
console.error(message);
console.debug(message);
}
showLog("hello world!");
</script>
</head>
<body>
請打開你的firebug查看控制檯輸出信息
</body>
</html>
console類的方法作用就是在firebug控制檯輸出一下信息,info,warn,error的輸出信息之前都會有一個不一樣的圖標
親,一定要用火狐瀏覽器,其他瀏覽器是不支持console類的方法的
這裏把測試信息輸出方法封裝在函數中的目的:
因爲你如果直接在你的js程序中寫console.log()方法的話,你測試完了之後要一個個刪除或註釋,如果代碼量大的話很不方便,但是現在做了這樣的封裝後,
當你不再需要測試的時候,只要把showLog函數中的語句註釋掉即可
本人親測,效果圖如下: