Will a tag like
开发者_开发技巧<span id="suchAndSuch" class="blah" rel="this.that.other" name="this.name"></span>
or
<div id="suchAndSuch" class="blah" rel="this.that.other" name="this.name"></div>
throw IE and/or FF to QM? According to W3C, those aren't standard attributes for those tags, but it does not say if it'll make them invalid.
Your help is much appreciated.
No, it will not throw a browser into quirks mode. Not having a DOCTYPE
or having a HTML comment (or any HTML content) before a DOCTYPE
will throw browsers into quirks mode.
If you can avoid using custom attributes, you should. If you cannot, you might want to consider using a HTML5 doctype, and then using data
attributes. For instance, what you wrote could be done like this:
<div id="suchAndSuch" class="blah" data-references="this.that.other" data-name="this.name"></div>
And that would still be valid, as well as supported by modern browsers (and even a number of older ones).
You have to be using a valid doctype and it needs to be the first thing found in the file. I haven't tested the behavior of a strict doctype and custom attributes but I know for sure that a transitional doctype works with custom attributes.
I think the key is to have a valid doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Quirks mode should only ever be triggered based on the (lack of) DOCTYPE
specified for the document.
In Firefox or IE, you can check the mode of a document by pasting the following in your address bar:
javascript:alert(document.compatMode)
The valid values for document.compatMode
are BackCompat
(for quirks mode) and CSS1Compat
(for standards/strict mode).
In Firefox, you can also right-click on a document and click "View Page Info". The mode will be listed near the top as "Render Mode".
You can check how a page is being rendered by the following:
In Firefox go to Tools > Page Info and look at the 'Render Mode'.
In IE8 click on Tools > Developer tools and look at the 'Document Mode' at the top right.
For example, this page is rendered in 'Standards compliance mode' in Firefox and 'IE8 Standards' in Internet Explorer.
Thx all for the prompt answers. I went ahead and tested each of the tags above with the W3C validator and it indeed is invalid X/HTML (strict, I believe) to use rel or name in divs or spans.
精彩评论