HTML 5数据属性和jQuery数据是否相同? [英] Are HTML 5 data- attribute and jQuery data same thing?

查看:78
本文介绍了HTML 5数据属性和jQuery数据是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML 5中,可以为元素之类的元素设置任意的数据"属性

In HTML 5 its possible to set arbitrary 'data-' attributes to elements like

<div data-blah="blah">

jQuery框架具有执行类似操作的方法(.data()等).我的问题是jQuery方法只是操纵并读取这些html5数据属性,还是它们引用了不同的jQuery类型的数据属性?

The jQuery framework has methods to do similar things (.data() etc). My question is do the jQuery methods just manipulate and read these html5 data attributes, or they are referring to different jQuery-type data-attributes?

推荐答案

不,完全不同. jQuery的.data()甚至早于HTML5.

No, totally different things. jQuery's .data() existed even before HTML5.

有关详细信息,请参见: http://api.jquery.com/data/.

See: http://api.jquery.com/data/ for details.

要从html标签获取HTML5数据属性值,请尝试:

To get HTML5 data- attribute value from html tag, try:

jQuery('selector here').attr('data-blah');

这篇关于HTML 5数据属性和jQuery数据是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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