使用"data- *"来表示.属性来替换"id"属性. HTML标记中的CSS属性用于CSS选择目的 [英] Using "data-*" attributes to replace the "id" attributes in HTML tags for CSS-Selecting Purpose

查看:84
本文介绍了使用"data- *"来表示.属性来替换"id"属性. HTML标记中的CSS属性用于CSS选择目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用"data-"属性替换元素(标签)中的"id"属性以进行css选择是个好主意,然后在自动化测试脚本中使用这些"data- *"属性吗?

Is it a good idea to use "data-" attributes to replace the "id" attributes in elements(tags) for css-selection purposes and then use those "data-*" attributes in automation testing scripts?

推荐答案

否.

在id上进行CSS选择和DOM树选择比选择任何其他属性要快得多.数据属性选择的效率可能不及某些浏览器中其他属性的选择.

CSS selection and DOM-tree selection on id is much faster than selection any other attribute. Data-attribute select might be less efficient than selection on other attributes in somebrowsers.

如果您滥用ID属性,则可能是个例外:在其中存储的不仅仅是标识符的内容(例如,复合数据或非唯一的内容).选择部分ID值(如果支持)会带来糟糕的性能.我建议您使用数据属性而不是滥用ID属性.

The exception might be if you are abusing id attributes: storing something that is not just an identifier in them (e.g. composite data or something not unique). Selecting parts of id values, if supported, gives terrible performance. I would recommend using data attributes over abusing id attributes.

这篇关于使用"data- *"来表示.属性来替换"id"属性. HTML标记中的CSS属性用于CSS选择目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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