将数据添加到XHTML标签 [英] Adding data to XHTML tags

查看:58
本文介绍了将数据添加到XHTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站是XHTML 1.1,我已经在页面上的< li> ÷ div> 标记中添加了"rel"属性,以存储数据页面上的jQuery脚本.验证我的页面时,出现错误:没有属性'rel'".那么,在HTML标签中存储任意数据的最佳方法是什么?

My website is XHTML 1.1, and I had added 'rel' attributes to the <li> and <div> tags on my page, to store data for a jQuery script on the page. When validating my page, I get the error: "there is no attribute 'rel'". So, what is the best way to store arbitrary data in HTML tags?

我正在为我的网站创建评论页面.输入评论后,它将通过AJAX发布,该评论将返回所有评论的JSON.然后,我查看"rel"值,以查看页面上已经有哪些评论,并且仅添加新评论.

I am working on a comments page for my website. When a comment is entered, it is POSTed via AJAX, which returns JSON of all comments. I then look at the 'rel' values to see which comments are already on the page, and only add the new ones.

jQuery代码可以正常工作,只是'rel'属性未通过验证.

The jQuery code works fine, it's just the 'rel' attributes don't validate.

推荐答案

虽然它不是XHTML规范,但您可以使用HTML5规范中包含的data- *属性.

While it's not XHTML spec, you could use the data-* attributes that are included in HTML5's spec.

http://html5doctor.com/html5-custom-data-attributes/

如果要保持与XHTML 1.1的完全兼容,则需要创建一个架构并将其名称空间包含在 html 元素中,该架构定义了要使用的属性,并且它们适用的元素.

If you want to remain fully XHTML 1.1 compliant, you'll need to create a schema and include its namespace in the html element, where the schema defines the attributes you want to use, and the elements to which they apply.

扩展XHTML

这篇关于将数据添加到XHTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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