問題描述
有時(shí)我會為我的一些控件添加一個(gè)屬性.喜歡:
Sometimes I add an attribute to some of my controls. Like:
<a href id="myLlink" isClimber="True">Chris Sharma</a>
我知道這不是一個(gè)有效的 html.但它在某些情況下對我有幫助.
I know it is not a valid html. But it helps me in some cases.
這是否被認(rèn)為是一種不好的做法?我的一個(gè)朋友說,內(nèi)網(wǎng)環(huán)境沒問題,但在互聯(lián)網(wǎng)上,搜索引擎可能會發(fā)現(xiàn)它不友好.
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.
如果這不是一個(gè)好的做法,最好的做法是什么?
If it is not a good practice, what are the best practicess?
謝謝
推薦答案
是的.這被認(rèn)為是一種不好的做法.您的 HTML(如果是 4.0)將無法成功驗(yàn)證.相反,像這樣添加一個(gè)類:
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>
記住你可以有多個(gè)類:
<a href id="myLlink" class="climber girl pretty" >...</a>
您可以使用 CSS 或 JQuery 根據(jù)這些類選擇內(nèi)容,并根據(jù)組合選擇性地覆蓋樣式:
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; }
這篇關(guān)于向 HTML 元素添加額外屬性是一種不好的做法嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!