3

What is the best way to check our web applications for errors such as "duplicate attribute"?

My development team tends to use Firefox and Firebug for web development. We've noticed some errors creeping into the codebase, usually duplicate attributes such as:

<div id="MyDiv" class="hide" class="interestingDiv">

We see no errors in Firebug's console nor can see anyway to get Firebug to report that there are errors.

We have noticed that Firefox itself IS aware of these errors. By clicking on "View Page Source", Firefox renders the second class in red and has a tooltip of "Duplicate Attribute". However we have to hunt through the code ourselves looking for any errors highlighted in red.

Surely there is a better way than manually looking at the code? What tools should we be using?

Thanks,

Phil

4

2 回答 2

4

Firefox 会自动纠正重复属性等 HTML 错误,即它只是忽略第二个属性。它不会将此作为错误暴露给它的Browser Console

Firebug 仅显示 Firefox 通过其 API 公开的错误消息,它不会自行分析 HTML/CSS/JavaScript。因此,由于 Firefox 不会为不正确的 HTML 生成错误消息,因此 Firebug 的控制台面板不会显示与此相关的任何内容。

尽管 Firefox 提供了另一种显示 HTML 错误的方法,但它的源视图。要到达那里,只需右键单击页面并从上下文菜单中选择查看页面源。此视图以红色突出显示重复的属性:

重复的 HTML 属性

您还有其他选择:

  1. 使用 HTML 验证器工具,例如Firefox或http://validator.w3.org/的Html Validator插件
  2. 您可能需要关注 Firefox错误 878364要求公开 HTML 错误。
于 2014-10-17T22:03:37.720 回答
0

W3 html 验证器将查看您的 html 并检查这些类型的错误:

http://validator.w3.org/

编辑:看起来有一个 Firefox 插件可以验证 HTML。我以前从未使用过它,但您可能想研究一下:

https://addons.mozilla.org/en-US/firefox/addon/html-validator/

于 2014-10-17T13:14:49.077 回答