说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

$.meta.setType(type, name)-JQuery API

HTML文档下载 WORD文档下载 PDF文档下载
$.meta.setType(type, name)设置元数据的类型. 元数据用JSON编码, 在JSON中的每个属性将成为该元素本身的属性.

$.meta.setType(type, name)

设置元数据的类型. 元数据用JSON编码, 在JSON中的每个属性将成为该元素本身的属性. 

There are three supported types of metadata storage: attr: Inside an attribute. The name parameter indicates which attribute. class: Inside the class attribute, wrapped in curly braces: { } elem: Inside a child element (e.g. a script tag). The name parameter indicates which element. The metadata for an element is loaded the first time the element is accessed via jQuery. As a result, you can define the metadata type, use $(expr) to load the metadata into the elements matched by expr, then redefine the metadata type and run another $(expr) for other elements.

 

返回值

undefined

 

参数

type (String): The encoding type 

name (String): The name of the attribute to be used to get metadata (optional) 

示例

说明:

Reads metadata from the class attribute

 

HTML 代码:

$.meta.setType("class") 

jQuery 代码:

<p id="one" class="some_class {item_id: 1, item_label: 'Label'}">This is a p</p> 

--------------------------------------------------------------------------------

 

说明:

 

Reads metadata from a "data" attribute

 

HTML 代码:

$.meta.setType("attr", "data") 

jQuery 代码:

<p id="one" class="some_class" data="{item_id: 1, item_label: 'Label'}">This is a p</p> 

--------------------------------------------------------------------------------

 

 

说明:

Reads metadata from a nested script element

 

HTML 代码:

$.meta.setType("elem", "script") 

jQuery 代码:

<p id="one" class="some_class"><script>{item_id: 1, item_label: 'Label'}</script>This is a p</p>

备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘