在元素上使用重复的类名? [英] Use duplicate class name on an element?

查看:84
本文介绍了在元素上使用重复的类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现有很多框架会在将新的类名添加到我认为会降低性能的元素上之前,检查重复的类名。

I found that there are many frameworks will check the duplicate class name before adding the new class name on the element that i think will slow down the performance.

在使用重复的类名时,它也将无冲突地应用CSS类。

It will also apply the CSS class without conflict while the duplicate class name is in used.

<div class="aa bb cc aa"></div>

是否可以添加一个类名,就像 elem.className + =''+'aa ee',即使元素具有重复的类名?

Is it OK to add a class name simply just like elem.className += ' ' + 'aa ee', even the element has duplicate class name?

推荐答案

具有重复的类名并不是什么错,只是多余。对性能的影响可能很小,但是如果您有很多重复,那只会真正有很大的不同。

There is nothing "wrong" with having a duplicate class name, it's just redundant. There's probably a small performance impact, but that'll only really make much difference if you have a lot of duplication.

此外,防止重复只会使事情保持整洁。

Also, preventing duplicates just helps to keep things tidy.

这篇关于在元素上使用重复的类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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