它是一个不好的做法,以增加额外的属性HTML元素? [英] Is it a bad practice to add extra attributes to html elements?

查看:104
本文介绍了它是一个不好的做法,以增加额外的属性HTML元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我的属性添加到我的一些控制。这样的:

Sometimes I add an attribute to some of my controls. Like:

<a href id="myLlink" isClimber="True">Chris Sharma</a>

我知道这是不是一个有效的HTML。但是,它可以帮助我在某些情况下。

I know it is not a valid html. But it helps me in some cases.

这被认为是一个不好的做法?我的一个朋友说,这是确定Intranet环境,但互联网上它可能无法找到搜索引擎友好。

Is this considered as a bad practice? A friend of mine says that it is ok for Intranet environment but on internet it might not be find friendly by search engines.

如果这不是一个好的做法,什么是最好的practicess?

If it is not a good practice, what are the best practicess?

感谢

推荐答案

是的。它被认为是一种不好的做法。您的HTML(如果它是4.0)将不会成功验证。相反,添加一个类,像这样:

Yes. It is considered a bad practice. Your HTML (if it's 4.0) won't validate successfully. Instead, add a class like so:

<a href id="myLlink" class="climber" >...</a>

记住,你可以有多个类:

Remember that you can have multiple classes:

<a href id="myLlink" class="climber girl pretty" >...</a>

您还可以使用CSS或基于jQuery这些类选择出来的东西,并基于选择的组合风格覆盖:

And you can use CSS or JQuery to select out stuff based on these classes, and selectively override style based on the combinations:

a.climber             { color: brown; }
a.climber.girl        { color: red; }
a.climber.girl.pretty { color: pink; }

这篇关于它是一个不好的做法,以增加额外的属性HTML元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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