English 中文(简体)
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 wraps 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.)





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签