可以在HTML5元素中多次指定相同的属性吗? [英] May the same attribute be specified more than one time in an HTML5 element?

查看:288
本文介绍了可以在HTML5元素中多次指定相同的属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在查看HTML5规范(W3C Recommendation 2014年10月28日),我找不到写入的地方是否可以为一个元素多次指定相同的属性。例如,有时属性样式具有非常长的值。所以出现了一个问题:为了更好的可读性,它可以分成几个样式属性吗?

I am looking now through the HTML5 specification (W3C Recommendation 28 October 2014) and I can not find where there is written whether the same attribute may be specified for an element more than one time. For example sometimes attribute style has a very long value. So a question arises: may it be split in several style attributes for better readability?

有人可以指出规范中的地方,表示允许或不?

Could somebody point to the place in the specification where there is said that it is allowed or not?

编辑:同样在3.2.5.8样式属性一节中写有所有HTML元素可能具有样式内容属性集 。如果同一属性最多只能指定一次,则属性集在此上下文中的含义是什么?

Also in Section "3.2.5.8 The style attribute" there is written "All HTML elements may have the style content attribute set". If the same attribute may be specified at most once then what does words attribute set mean in this context?

推荐答案

HTML5规范, 第8.2.4.35节 - 属性名称状态 表示:

The HTML5 spec, Section 8.2.4.35 - 'Attribute name state' says:


当用户代理离开属性名称状态时(并且在发出之前)标记令牌(如果适用),必须将完整属性的名称与同一令牌上的其他属性进行比较;如果令牌上已经存在具有完全相同名称的属性,那么这是一个解析错误,必须从令牌中删除新属性。

When the user agent leaves the attribute name state (and before emitting the tag token, if appropriate), the complete attribute's name must be compared to the other attributes on the same token; if there is already an attribute on the token with the exact same name, then this is a parse error and the new attribute must be removed from the token.

所以,为了回答你的问题,它是无效的HTML。

So, to answer your question, it's invalid HTML.

这篇关于可以在HTML5元素中多次指定相同的属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆