[英]What is the difference between id and js-.. for js apeel in css?
This question relates to the article http://davidwalsh.name/css-do . 该问题与文章http://davidwalsh.name/css-do有关 。 What are the differences and advantages these approaches?
这些方法有什么区别和优势?
<div class="do-launch-login">...</div>
<a class="do-close-modal">...</a>
<input class="do-autocomplete" />
and 和
<div id ="login" class="launch-login">...</div>
<a id="close" class="close-modal">...</a>
<input id="autocomplete" class="clautocomplete" />
The author calls them do-
prefixes, i call them (and use them as) js-
or jQ-
prefixes. 作者称它们为
do-
前缀,我称它们为js-
或jQ-
前缀(并将它们用作)。
Javascript has a whole scale of possible applications in DOM manipulation... than just a do-
Javascript在DOM操作中具有可能的全部应用范围……而不仅仅是
do-
Those prefixes are to indicate classes used exclusively by JS , means you cannot find them in ie: style.css
but rather as part of some Javascript logic in script.js
. 这些前缀表示JS专用的类 ,这意味着您无法在ie:
style.css
找到它们,而只能作为script.js
中某些Javascript逻辑的一部分来找到它们。
Also you cannot use ID multiple times cause ID should be unique-per-page , so, classes in any case, spiced with a prefix to distinguish it's application. 同样, 您不能多次使用ID,因为ID应该是每页唯一的 ,因此,在任何情况下,类都必须加上前缀以区分其应用。
(hm... do-
... still seems pretty funny.) (HM ...
do-
...似乎仍然非常有趣。)
Personally for me, I generate a lot of dynamic HTML on the fly for my web applications. 就我个人而言,我会为我的Web应用程序动态生成大量动态HTML。 Because of this, I try to never use IDs as I make multiple instances of the same HTML objects.
因此,在创建同一HTML对象的多个实例时,我尽量不要使用ID。
It is considered terrible practice to ever have a duplicate of an ID, so I always use class names as selectors. 曾经有一个ID的重复被认为是可怕的做法,所以我总是使用类名作为选择器。
But that's just me. 但这就是我。
Id should only be used for a single thing. Id仅可用于单一事物。 However a class can be given to many different things.
但是,可以为许多不同的事物提供类。 You could easily google this for more in depth answer
您可以轻松地在Google上搜索更多答案
Some consider use of id in css a bad practice, because of: 一些人认为在CSS中使用id是一种不好的做法,因为:
- The element is not re-usable on that page.
该元素不可在该页面上重复使用。
- This is the beginning downward sprial into specificity.
这是特异性下降的开始。
- Usually, IDs refer to something specific, and abstracting would be tough.
通常,ID指的是特定的东西,而抽象将很困难。
- Any performance gains picked up by using id, is negated by adding any other selector to the left for that id
通过使用id获得的任何性能提升,可以通过在该id的左侧添加任何其他选择器来抵消
quoted from http://screwlewse.com/ 引用自http://screwlewse.com/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.