开发者

When using HTML5 Microdata, should the 'itemscope' and 'itemtype' always be used on the same element?

I'm trying to understand the reason behind the existence of two attributes instead of just making the element holding the 'itemtype' the one that wrap开发者_开发技巧s the scope for the item.

Is it valid to have 'itemtype' attribute on one element and 'itemscope' attribute in some other? like this:

<section itemtype="http://data-vocabulary.org/Person">
    <div itemscope>
        <span itemprop="name">Alonso Torres</span>
    </div>
</section>

If this case is not valid then why the existence of the 'itemscope' attribute at all? Why the spec didn't come up with the idea of making the element holding the 'itemtype' attribute to be the one which sets the scope. That would have make sense for me.


You're right, the itemscope attribute seems redundant. Someone else pointed this out on the W3C's HTML mailing list: http://lists.w3.org/Archives/Public/public-html-bugzilla/2011Jan/0517.html

The answer ( http://lists.w3.org/Archives/Public/public-html-bugzilla/2011Jan/0523.html ) was that:

The HTML spec editor did user-testing of the feature earlier, and if I recall correctly, several of the test subjects found it much easier if there was an explicit indicator of the container, rather than it being implicit due to the type.

In other words, it's better for attributes to have a single clear definition than multiple implied definitions. Not sure I agree but that's the official view.


itemscope is mandatory if itemtype is used on the same element

The example you show is invalid. The spec has been updated to include this:

The itemtype attribute must not be specified on elements that do not have an itemscope attribute specified.

Here, "must not" is to interpreted as in RFC2119: "the definition is an absolute prohibition of the specification".


I don't believe that it is useful to place an itemtype attribute anywhere but on the same element as the itemscope attribute. The spec says:

The type for an item is given as the value of an itemtype attribute on the same element as the itemscope attribute.

The reasons why two attributes are needed isn't clear to me either. Semantically they serve different purposes, so for clarity of usage it may have seemed more sensible. For simple use, it's possible to create an item using itemscope without giving it a type. That means that itemscope is a boolean attribute, whereas itemtype takes a string value. It's not possible in HTML for an attribute to behave as boolean when used without a value, and a string when used with one, so separate attributes makes sense.

I know that Google did a usability study on the Microdata mark-up before it was announced, so it was likely that such questions were addressed there and that the separate attributes was the preferred outcome. (Although that study also resulted in a preference for itemref being an element, not an attribute, something that was subsequently changed.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜