六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 28|回复: 0

Firebug快速入门(一)

[复制链接]

升级  0.95%

325

主题

325

主题

325

主题

探花

Rank: 6Rank: 6

积分
1019
 楼主| 发表于 2013-1-29 09:22:13 | 显示全部楼层 |阅读模式
<!--[if gte mso 9]><xml> <w:WordDocument>  <w:View>Normal</w:View>  <w:Zoom>0</w:Zoom>  <w:PunctuationKerning />  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>  <w:ValidateAgainstSchemas />  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>  <w:Compatibility>   <w:SpaceForUL />   <w:BalanceSingleByteDoubleByteWidth />   <w:DoNotLeaveBackslashAlone />   <w:ULTrailSpace />   <w:DoNotExpandShiftReturn />   <w:AdjustLineHeightInTable />   <w:BreakWrappedTables />   <w:SnapToGridInCell />   <w:WrapTextWithPunct />   <w:UseAsianBreakRules />   <w:DontGrowAutofit />   <w:UseFELayout />  </w:Compatibility>  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles></xml><![endif]--><!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"\@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;} /* List Definitions */ @list l0{mso-list-id:2114936771;mso-list-template-ids:182877916;}@list l0:level1{mso-level-number-format:chinese-counting-thousand;mso-level-text:%1、;mso-level-tab-stop:21.0pt;mso-level-number-position:left;margin-left:21.0pt;text-indent:-21.0pt;mso-ansi-font-size:12.0pt;mso-bidi-font-size:12.0pt;mso-ansi-font-weight:bold;}@list l0:level2{mso-level-text:"%1\.%2";mso-level-tab-stop:49.6pt;mso-level-number-position:left;margin-left:49.6pt;text-indent:-1.0cm;}@list l0:level3{mso-level-text:"%1\.%2\.%3";mso-level-tab-stop:70.9pt;mso-level-number-position:left;margin-left:70.9pt;text-indent:-1.0cm;}@list l0:level4{mso-level-text:"%1\.%2\.%3\.%4";mso-level-tab-stop:99.2pt;mso-level-number-position:left;margin-left:99.2pt;text-indent:-35.4pt;}@list l0:level5{mso-level-text:"%1\.%2\.%3\.%4\.%5";mso-level-tab-stop:127.55pt;mso-level-number-position:left;margin-left:127.55pt;text-indent:-42.5pt;}@list l0:level6{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6";mso-level-tab-stop:163.0pt;mso-level-number-position:left;margin-left:163.0pt;text-indent:-2.0cm;}@list l0:level7{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7";mso-level-tab-stop:191.35pt;mso-level-number-position:left;margin-left:191.35pt;text-indent:-63.8pt;}@list l0:level8{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8";mso-level-tab-stop:219.7pt;mso-level-number-position:left;margin-left:219.7pt;text-indent:-70.9pt;}@list l0:level9{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.%9";mso-level-tab-stop:255.1pt;mso-level-number-position:left;margin-left:255.1pt;text-indent:-85.0pt;}ol{margin-bottom:0cm;}ul{margin-bottom:0cm;}--><!--[if gte mso 10]><mce:style><!  /* Style Definitions */ table.MsoNormalTable{mso-style-name:普通表格;mso-tstyle-rowband-size:0;mso-tstyle-colband-size:0;mso-style-noshow:yes;mso-style-parent:"";mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-para-margin:0cm;mso-para-margin-bottom:.0001pt;mso-pagination:widow-orphan;font-size:10.0pt;font-family:"Times New Roman";mso-ansi-language:#0400;mso-fareast-language:#0400;mso-bidi-language:#0400;}--><!--[endif]-->

一、<!--[endif]-->前言
Firebug是Firefox下的一款开发类插件,现属于Firefox的 五星级强力推荐插件之一。它集HTML查看和编辑、Javascript控制台、网络状况监视器于一体,是开发JavaScript、CSS、HTML和 Ajax的得力助手。Firebug如同一把精巧的瑞士军刀,从各个不同的角度剖析Web页面内部的细节层面,给Web开发者带来很大的便利。这是一款让 人爱不释手的插件,如果你以前没有接触过它,也许在阅读本文之后,会有一试的欲望。
Firebug有6个功能:Console控制台、Html查看器、Css查看器、Script 调试器 、Dom查看器、网络状况监视。(图中另一个插件YSlow也会详细介绍),下文将主要介绍介绍这几方面的功能。

<!--[if gte mso 9]><xml> <w:WordDocument>  <w:View>Normal</w:View>  <w:Zoom>0</w:Zoom>  <w:PunctuationKerning />  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>  <w:ValidateAgainstSchemas />  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>  <w:Compatibility>   <w:SpaceForUL />   <w:BalanceSingleByteDoubleByteWidth />   <w:DoNotLeaveBackslashAlone />   <w:ULTrailSpace />   <w:DoNotExpandShiftReturn />   <w:AdjustLineHeightInTable />   <w:BreakWrappedTables />   <w:SnapToGridInCell />   <w:WrapTextWithPunct />   <w:UseAsianBreakRules />   <w:DontGrowAutofit />   <w:UseFELayout />  </w:Compatibility>  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles></xml><![endif]--><!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"\@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;}h3{mso-margin-top-alt:auto;margin-right:0cm;mso-margin-bottom-alt:auto;margin-left:0cm;mso-pagination:widow-orphan;mso-outline-level:3;font-size:13.5pt;font-family:宋体;mso-bidi-font-family:宋体;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;} /* List Definitions */ @list l0{mso-list-id:2114936771;mso-list-template-ids:182877916;}@list l0:level1{mso-level-number-format:chinese-counting-thousand;mso-level-text:%1、;mso-level-tab-stop:21.0pt;mso-level-number-position:left;margin-left:21.0pt;text-indent:-21.0pt;mso-ansi-font-size:12.0pt;mso-bidi-font-size:12.0pt;mso-ansi-font-weight:bold;}@list l0:level2{mso-level-text:"%1\.%2";mso-level-tab-stop:49.6pt;mso-level-number-position:left;margin-left:49.6pt;text-indent:-1.0cm;}@list l0:level3{mso-level-text:"%1\.%2\.%3";mso-level-tab-stop:70.9pt;mso-level-number-position:left;margin-left:70.9pt;text-indent:-1.0cm;}@list l0:level4{mso-level-text:"%1\.%2\.%3\.%4";mso-level-tab-stop:99.2pt;mso-level-number-position:left;margin-left:99.2pt;text-indent:-35.4pt;}@list l0:level5{mso-level-text:"%1\.%2\.%3\.%4\.%5";mso-level-tab-stop:127.55pt;mso-level-number-position:left;margin-left:127.55pt;text-indent:-42.5pt;}@list l0:level6{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6";mso-level-tab-stop:163.0pt;mso-level-number-position:left;margin-left:163.0pt;text-indent:-2.0cm;}@list l0:level7{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7";mso-level-tab-stop:191.35pt;mso-level-number-position:left;margin-left:191.35pt;text-indent:-63.8pt;}@list l0:level8{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8";mso-level-tab-stop:219.7pt;mso-level-number-position:left;margin-left:219.7pt;text-indent:-70.9pt;}@list l0:level9{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.%9";mso-level-tab-stop:255.1pt;mso-level-number-position:left;margin-left:255.1pt;text-indent:-85.0pt;}ol{margin-bottom:0cm;}ul{margin-bottom:0cm;}-->
<!--[if gte mso 10]><mce:style><!  /* Style Definitions */ table.MsoNormalTable{mso-style-name:普通表格;mso-tstyle-rowband-size:0;mso-tstyle-colband-size:0;mso-style-noshow:yes;mso-style-parent:"";mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-para-margin:0cm;mso-para-margin-bottom:.0001pt;mso-pagination:widow-orphan;font-size:10.0pt;font-family:"Times New Roman";mso-ansi-language:#0400;mso-fareast-language:#0400;mso-bidi-language:#0400;}--><!--[endif]--><!--[if !supportLists]-->二、<!--[endif]-->Console控制台

控制台能够显示当前页面中的javascript错误以及警告,并提示出错的文件和行号,方便调试,这些错误提示比起浏览器本身提供的错误提示更加 详细且具有参考价值。而且在调试Ajax应用的时候也是特别有用,你能够在控制台里看到每一个XMLHttpRequests请求post出去的参数、 URL,http头以及回馈的内容,原本似乎在幕后运作的程序被清清楚楚地展示在你面前。

你还能在控制台中查看变量内容,直接运行javascript语句,就算是大段的javascript程序也能够正确运行并拿到运行期的信息。


<!--[if gte mso 9]><xml> <w:WordDocument>  <w:View>Normal</w:View>  <w:Zoom>0</w:Zoom>  <w:PunctuationKerning />  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>  <w:ValidateAgainstSchemas />  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>  <w:Compatibility>   <w:SpaceForUL />   <w:BalanceSingleByteDoubleByteWidth />   <w:DoNotLeaveBackslashAlone />   <w:ULTrailSpace />   <w:DoNotExpandShiftReturn />   <w:AdjustLineHeightInTable />   <w:BreakWrappedTables />   <w:SnapToGridInCell />   <w:WrapTextWithPunct />   <w:UseAsianBreakRules />   <w:DontGrowAutofit />   <w:UseFELayout />  </w:Compatibility>  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles></xml><![endif]--><!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"\@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}--><!--[if gte mso 10]><mce:style><!  /* Style Definitions */ table.MsoNormalTable{mso-style-name:普通表格;mso-tstyle-rowband-size:0;mso-tstyle-colband-size:0;mso-style-noshow:yes;mso-style-parent:"";mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-para-margin:0cm;mso-para-margin-bottom:.0001pt;mso-pagination:widow-orphan;font-size:10.0pt;font-family:"Times New Roman";mso-ansi-language:#0400;mso-fareast-language:#0400;mso-bidi-language:#0400;}--><!--[endif]-->
控制台还有个重要的作用就是查看脚本的log, 从前你也许习惯了使用alert来打印变量,但是Firebug给我们带来了一个新朋友 —— console.log, 最简单的打印日志的语法是这样的:

console.log("hello world")

此外console对象还有很多相应的调试方法

<!--[if gte mso 9]><xml> <w:WordDocument>  <w:View>Normal</w:View>  <w:Zoom>0</w:Zoom>  <w:PunctuationKerning />  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>  <w:ValidateAgainstSchemas />  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>  <w:Compatibility>   <w:SpaceForUL />   <w:BalanceSingleByteDoubleByteWidth />   <w:DoNotLeaveBackslashAlone />   <w:ULTrailSpace />   <w:DoNotExpandShiftReturn />   <w:AdjustLineHeightInTable />   <w:BreakWrappedTables />   <w:SnapToGridInCell />   <w:WrapTextWithPunct />   <w:UseAsianBreakRules />   <w:DontGrowAutofit />   <w:UseFELayout />  </w:Compatibility>  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles></xml><![endif]--><!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"\@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}--><!--[if gte mso 10]><mce:style><!  /* Style Definitions */ table.MsoNormalTable{mso-style-name:普通表格;mso-tstyle-rowband-size:0;mso-tstyle-colband-size:0;mso-style-noshow:yes;mso-style-parent:"";mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-para-margin:0cm;mso-para-margin-bottom:.0001pt;mso-pagination:widow-orphan;font-size:10.0pt;font-family:"Times New Roman";mso-ansi-language:#0400;mso-fareast-language:#0400;mso-bidi-language:#0400;}--><!--[endif]-->

函数

说明

console.log(object[,  object, ...])

向控制台输出一个信息。可以输入多个参数,输出将已空格分隔各参数输出。

第一参数可以包含格式化文本,例如:

console.log(‘这里有%d个%s’,count,apple);

字符串格式:

%s :字符串。

%d, %i:数字。

%f: 浮点数。

%o -超链接对象。

console.debug(object[,  object, ...])

向控制台输出一个信息,信息包含一个超链接链接到输出位置。

console.info(object[,  object, ...])

向控制台输出一个带信息图标和背景颜色的信息,信息包含一个超链接链接到输出位置。

console.warn(object[,  object, ...])

向控制台输出一个带警告图标和背景颜色的信息,信息包含一个超链接链接到输出位置。

console.error(object[,  object, ...])

向控制台输出一个带错误图标和背景颜色的信息,信息包含一个超链接链接到输出位置。

console.assert(expression[,  object, ...])

测试一个表示是否为true,如果为false,提交一个例外信息到控制台。

console.dir(object)

列出对象的所有属性。

console.dirxml(node)

列出HTML或XML Element的XML源树。

console.trace()

输出堆栈的调用入口。

console.group(object[,  object, ...])

将信息分组再输出到控制台。通过console.groupEnd()结束分组。

console.groupEnd()

结束分组输出。

console.time(name)

创建一个名称为name的计时器,计算代码的执行时间,调用console.timeEnd(name)停止计时器并输出执行时间。

console.timeEnd(name)

停止名称为name的计时器并输出执行时间。

console.profile([title])

开始对脚本进行性能测试,title为测试标题。

console.profileEnd()

结束性能测试。

console.count([title])

计算代码的执行次数。titile作为输出标题。

您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表