HTML元素上的ID属性是否为空?
<div id=""></div>
我正在使用一个模板,其中元素的ID由一个可能不总是具有值的变量设置,我想知道是否可能导致任何不可预见的问题。
编辑:“变量”实际上是Django模板中的可编辑区域(块)。这意味着我无法对其进行任何条件逻辑。
<div id="{% block id %}{% endblock %}">
而不是:
<div {% block id %}{% endblock %}>
哪些在子模板中必须被继承为:
{% block id %}id="whatever"{% endblock %}
解决方法
根据W3C:
ID and NAME tokens must begin with a
letter ([A-Za-z]) and may be followed
by any number of letters,digits
([0-9]),hyphens (“-“),underscores
(“_”),colons (“:”),and periods
(“.”).
这将表明属性的空白值根据上述定义无效。
Syntax of attribute value does not
conform to declared value
<div id="">something</div>
The value of an attribute contained something that is not allowed by the specified Syntax for that type of attribute. For instance,the “selected” attribute must be either minimized as “selected” or spelled out in full as “selected=”selected””; the variant “selected=””” is not allowed.