那么如果自定义HTML属性不是有效的XHTML呢? [英] So what if custom HTML attributes aren't valid XHTML?

查看:79
本文介绍了那么如果自定义HTML属性不是有效的XHTML呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是有些人不赞成的原因,但这真的很重要吗?我认为,他们提供的与JavaScript交互以及从服务器存储和发送信息的能力超过了验证问题。我错过了什么吗?什么是无效HTML的后果?并且不会有定制的DTD解决它们吗?

解决方案

衍生产品是w3c在2,5,10年并创建一个同名的属性。现在你的页面被打破了。

HTML5将为合法的自定义属性(如data-myattr =foo)提供数据属性类型,因此您可以开始使用现在并且对于将来的名称冲突是合理安全的。



最后,您可能会忽视定制逻辑是类属性背后的理性。虽然它通常被认为是一种风格属性,但它实际上是一种在元素上设置自定义元属性的合法方法。不幸的是,你基本上只限于布尔属性,这就是为什么HTML5添加数据前缀。



顺便说一句,基本布尔我的意思是原则上。实际上,没有什么能够阻止你在类名中使用分隔符来定义自定义值和属性。

class =document docId .56权限.RW


I know that is the reason some people don't approve of them, but does it really matter? I think that the power that they provide, in interacting with JavaScript and storing and sending information from and to the server, outweighs the validation concern. Am I missing something? What are the ramifications of "invalid" HTML? And wouldn't a custom DTD resolve them anyway?

解决方案

The ramification is that w3c comes along in 2, 5, 10 years and creates an attribute with the same name. Now your page is broken.

HTML5 is going to provide a data attribute type for legal custom attributes (like data-myattr="foo") so maybe you could start using that now and be reasonably safe from future name collisions.

Finally, you may be overlooking that custom logic is the rational behind the class attribute. Although it is generally thought of as a style attribute it is in reality a legal way to set custom meta-properties on an element. Unfortunately you are basically limited to boolean properties which is why HTML5 is adding the data prefix.

BTW, by "basically boolean" I mean in principle. In reality there is nothing to stop you using a seperator in your class name to define custom values as well as attributes.

class="document docId.56 permissions.RW"

这篇关于那么如果自定义HTML属性不是有效的XHTML呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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