HTML属性的长度是否有限制? [英] Is there a limit to the length of HTML attributes?

查看:137
本文介绍了HTML属性的长度是否有限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用HTML5风格的数据属性( data-foo = bar)在一个新的应用程序中,并且在一个地方存储一个公平的数据(100个字符以上)将非常方便。虽然我怀疑这个数量没有问题,但它提出了多少太多的问题?

解决方案

HTML 4



从HTML 4的角度来看,属性是SGML构造。它们的限制在 HTML 4的SGML声明中定义:

 
QUANTITY SGMLREF
ATTCNT 60 - 增加 -
ATTSPLEN 65536 - 这是最大值 -
LITLEN 65536 - 在声明中允许 -
NAMELEN 65536 - 避免实际的固定限制 -
PILEN 65536 - HTML UA的实现 -
TAGLVL 100
TAGLEN 65536
GRPGTCNT 150
GRPCNT 64

这里所讨论的值是ATTSPLEN,它是极限在元素的属性规范列表(应该是该元素的所有属性的总大小)。上面的说明提到应该避免使用固定的限制,但是,在大多数实现中,除了可用内存之外,可能没有实际的限制。

HTML 5



HTML 5似乎不同,因为规范说,这个HTML版本因此返回到非SGML基础。



稍后,在描述如何解析HTML 5时,以下段落出现(强调):


下面介绍的算法将
在DOM树的深度上生成
,或在标签的长度上
名称,属性名称,属性
文本节点等。虽然鼓励
的实现者避免
的任意限制,但确认
实际的担忧可能是
强制用户代理实施嵌套
深度c onstraints。


所以我想这就是你的答案。


How long is too long for an attribute value in HTML?

I'm using HTML5 style data attributes (data-foo="bar") in a new application, and in one place it would be really handy to store a fair whack of data (upwards of 100 characters). While I suspect that this amount is fine, it raises the question of how much is too much?

解决方案

HTML 4

From an HTML 4 perspective, attributes are an SGML construct. Their limits are defined in the SGML Declaration of HTML 4:

         QUANTITY SGMLREF
                  ATTCNT   60      -- increased --
                  ATTSPLEN 65536   -- These are the largest values --
                  LITLEN   65536   -- permitted in the declaration --
                  NAMELEN  65536   -- Avoid fixed limits in actual --
                  PILEN    65536   -- implementations of HTML UA's --
                  TAGLVL   100
                  TAGLEN   65536
                  GRPGTCNT 150
                  GRPCNT   64

The value in question here is "ATTSPLEN" which would be the limit on an element's attribute specification list (which should be the total size of all attributes for that element). The note above mentions that fixed limits should be avoided, however, so it's likely that there is no real limit other than available memory in most implementations.

HTML 5

HTML 5 seems to be different, as the spec says, "This version of HTML thus returns to a non-SGML basis."

Later on, when describing how to parse HTML 5, the following passage appears (emphasis added):

The algorithm described below places no limit on the depth of the DOM tree generated, or on the length of tag names, attribute names, attribute values, text nodes, etc. While implementors are encouraged to avoid arbitrary limits, it is recognized that practical concerns will likely force user agents to impose nesting depth constraints.

So I suppose that is your answer.

这篇关于HTML属性的长度是否有限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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