How can I use HTML5 Data Attributes in XHTML?

我的未来我决定 提交于 2020-01-03 08:36:18

问题


Does anyone know how the HTML5 data attributes (data-*) can be implemented in XHTML without rendering the markup as invalid?

Is there a custom namespacing hack that would allow this on existing HTML elements?


回答1:


You could use XHTML5. Then your mark-up would be XML, and valid XHTML5.

I think you could also use XML namespacing to use them on XHTML1 — I’m not very familiar with XML, so I’m not sure.

I think that both of these methods technically require you to serve your pages as XML (instead of text/html), which Internet Explorer doesn’t support. But I suspect they’d work just fine in browsers even if you didn’t.




回答2:


I don't know if this is a general solution, but it worked for me:

<ul data-clearing="">

Ie. just append ="" to make it a valid XML attribute.



来源:https://stackoverflow.com/questions/3285925/how-can-i-use-html5-data-attributes-in-xhtml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!