Html 可以将 id/class 添加到 <link> 标签吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10077475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it okay to add id/class to <link> tag?
提问by AlexCheuk
Is it okay to do this?
这样做可以吗?
<link rel="stylesheet" href="css/mobile/load.css" id="stylesheet_mobile" />
so I can use JavaScript to dynamically disable stylesheets?
所以我可以使用 JavaScript 来动态禁用样式表?
回答by xbonez
According to HTML 4.01 Transitional, id
, class
are document-wide selectors, and thus it is ok to have them in the link
element.
根据HTML 4.01 Transitional, id
,class
是文档范围的选择器,因此可以在link
元素中使用它们。
回答by animuson
Yes, you can. The core attributes are allowed on the <link>
element, which includes style
, class
, id
, and title
. Although, since it's not a rendered element, classes and styles won't have any effect.
是的你可以。核心属性允许在上<link>
元件,其中包括style
,class
,id
,和title
。虽然,由于它不是渲染元素,类和样式不会有任何影响。
<!ENTITY % coreattrs
"id ID #IMPLIED -- document-wide unique id --
class CDATA #IMPLIED -- space-separated list of classes --
style %StyleSheet; #IMPLIED -- associated style info --
title %Text; #IMPLIED -- advisory title --"
>
回答by Zirak
Yes. There are certain attributes that may be specified on every html element. id
and class
are among them.
是的。可以在每个 html 元素上指定某些属性。id
并class
在其中。
For a complete list in the html5 spec: http://developers.whatwg.org/elements.html#global-attributes
有关 html5 规范中的完整列表:http: //developers.whatwg.org/elements.html#global-attributes
The spec for the link element: http://developers.whatwg.org/semantics.html#the-link-element
链接元素的规范:http: //developers.whatwg.org/semantics.html#the-link-element
And in html4.1: http://www.w3.org/TR/html401/struct/links.html#h-12.3
在 html4.1 中:http: //www.w3.org/TR/html401/struct/links.html#h-12.3
回答by Florian Margaine
Yup, it is. It is not recommended though, as this'd mean loading several files (multiple HTTP requests) as opposed to loading one bigger file (but one HTTP request only).
是的,是的。但是不推荐这样做,因为这意味着加载多个文件(多个 HTTP 请求)而不是加载一个更大的文件(但仅一个 HTTP 请求)。