XHTML 1.0 Strict中的自定义数据 [英] Custom data in XHTML 1.0 Strict

查看:105
本文介绍了XHTML 1.0 Strict中的自定义数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的html中使用了一些自定义属性,用于jquery的东西。我在HTML5中看到了 data-XYZ 属性,但我需要是xhtml 1.0 strict。我还有什么其他选择?

您可以使用 jQuery MetaData插件,它允许您以JSON格式在class属性中编写数据:

 < li class =someclass {some:'data'} anotherclass> ...< / li> 

然后在你的jQuery中,获取数据:

  var data = $('li.someclass')。metadata(); 
if(data.some&; data.some =='data')
alert('It Worked!');

这应该符合您对xhtml 1.0严格的要求,并且还允许您使用插件和 - 播放解决方案:)

I use some custom attributes in my html, for jquery stuff. I saw there are data-XYZ attributes in HTML5, but I need to be xhtml 1.0 strict. What other options do I have?

解决方案

You can use the jQuery MetaData plugin which allows you to write data in the class attribute in JSON format:

<li class="someclass {some: 'data'} anotherclass">...</li>

Then in your jQuery, to get at the data:

var data = $('li.someclass').metadata();
if ( data.some && data.some == 'data' )
    alert('It Worked!');

This should meet your requirements of being xhtml 1.0 strict, and also allows you to use a plug-and-play solution :)

这篇关于XHTML 1.0 Strict中的自定义数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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