自定义属性vs data- *属性 [英] custom attribute vs data-* attribute

查看:230
本文介绍了自定义属性vs data- *属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道数据属性是HTML 5的一部分。它似乎是使用它来序列化一些标记数据的好选择。所以有人使用data-bind =xxx。但是我可以使用bind =xxx。它似乎违反了规范的模式,但实际上它在所有浏览器中都有效。所以我的问题是,什么是实际的原因(不是在理论上),像性能,我不应该使用海关属性就像bind =xxx。我知道bind属性不是保留属性。

I know that data- Attributes is part of HTML 5. It seems to be a good choice to use it to serialize some data in markup. So there are people using data-bind="xxx" . But can I just use bind="xxx". It seems violate schema, of specification, but practically it works in all browser. So my question is, what is the practical reason (not in theory) like performance that I should not use customs attribute just like bind="xxx". I know bind attribute is not reserved attribute.

谢谢

推荐答案

实际上,一些浏览器可以实现具有完全不同含义的 bind

Practically, some browser can implement bind with a totally different meaning.

您正在使用它来进行Knockout,但是假设新意义是不同的。当您更改一个元素上的内联CSS时,它应该根据bind属性中的选择器将其更改为另一个元素。

You're using it for Knockout, but hypothetically the new meaning is different. When you change the inline CSS on one element, it should change it on another element based on a selector in the bind attribute.

有理由尊重标准并使用私有(例如数据)或供应商特定的前缀。

There's a reason to respect standards and use private (e.g. data-) or vendor-specific prefixes.

这篇关于自定义属性vs data- *属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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