jQuery API | jQuery API 中英文对照版 - jQuery在线查询手册 |
$.meta.setType(type, name) |
$.meta.setType(type, name)Sets the type of metadata to use. Metadata is encoded in JSON, and each property in the JSON will become a property of the element itself. 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 参数
示例说明: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> |