1.0的版本是这样的$.meta
2.0的版本是这样的$.metadata
很多插件的编写都用到了这个插件,个人感觉这个东西应该是jquery官方的。推荐使用2.0的版本,因为现在官方上就是2.0的文档(
http://docs.jquery.com/Plugins/Metadata),1.0的,我个人还没看懂,倒是2.0的例子运行很正常。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="jquery.metadata.2.0/jquery.metadata.2.0/test/jquery.js"></script>
<!-- 这里既引用了1.0又引用了2.0,就是为了说明它们之间没有冲突,我的理解是以前的优秀插件里面使用了1.0,但是1.0的问题确实有,所以2.0把meta改成metadata 这样就不会相互冲突了-->
<script type="text/javascript" src="jquery.metadata.2.0/jquery.metadata.2.0/jquery.metadata.js"></script>
<script type="text/javascript" src="jquery.metadata.1.0/jquery.metadata.1.0/jquery.metadata.js"></script>
<script language="javascript">
$(document).ready(function(){
alert($(".media").metadata().src);
alert($('li.someclass').metadata().some);
});
</script>
</head>
<body>
<OBJECT class="media {src:'/tems/upload/192168.mp3'}" data="[object Object]"></OBJECT>
<li class="someclass {some: 'data'} anotherclass">...</li>
OR
<li data="{some:'random', json: 'data'}">...</li>
OR
<li><script type="data">{some:"json",data:true}</script> ...</li>
<script language="javascript">
var data = $('li.someclass').metadata();
if ( data.some && data.some == 'data' )
alert('It Worked!');
</script>
</body>
</html>
翻译:
attr:内部属性,参数名字指向属性名
class:内部类的属性,用{}包裹
elem:内部子元素 (如script标签).参数的名字指向元素名。
函数:
metadata( options ) Returns: Object
Extracts, caches, and returns metadata from the first element in the jQuery collection.
Arguments:
options (Optional) Options
A set of key/value pairs that define the type of metadata to be extracted. All options are optional.
Options:
metadata( options )中的options有三种:type、name、single
type String Default: 'class'
Specify the expected locations of metadata for the element. Possible values are 'class': search in the class attribute, 'elem': search for an element inside the element being searched, and 'attr': search in a custom attribute on the element.
Searches for metadata in a custom element attribute instead of in the class.
$(".selector").metadata({
type: 'attr'
})
name String Default: 'metadata'
When type is 'attr', specify the name of the custom attribute for which to search. When type is 'elem', specify the tag name of the element for which to search.
Searches for metadata in a custom element attribute with a name of 'jdata'.
$(".selector").metadata({
type: 'attr',
name: 'jdata'
})
single String Default: 'metadata'
The name given to the data extracted from the element in the jQuery cache.
Stores and retrieves the data extracted into an item named 'jdata' in the jQuery cache.
$(".selector").metadata({
single: 'jdata'
})
Examples:
Gets metadata from the class attribute.
<li class="someclass {some: 'data'} anotherclass">...</li>
<script>alert($('li.someclass').metadata().some);</script>
Gets metadata from a custom attribute.
<li data="{some:'random', json: 'data'}">...</li>
<script>alert($('li.someclass').metadata({type:'attr',name:'data'}).some);</script>
Gets metadata from a child element.
<li class="someclass"><script type="application/json">{some:"json",data:true}</script>...</li>
<script>alert($('li.someclass').metadata({type:'elem',name:'script'}).some);</script>
jQuery.metadata.setType( type, name ) Returns: null
Sets the default type and name options for all following metadata requests.
Arguments:
type String
Specify the expected location of metadata for the element. Possible values are 'class' (default): search in the class attribute, 'elem': search for an element inside the element being searched, and 'attr': search in a custom attribute on the element.
name String
The name of the tag or attribute for which to search depending on the value of the 'type' option.
Examples:
* Code
Setup metadata plugin to look for a custom attribute.
<li data="{some:'random', json: 'data'}" class="someclass">...</li>
<script>
$.metadata.setType('attr','data');
alert($('li.someclass').metadata().some);
</script>
jQuery.metadata.get( elem, options ) Returns: Object
Sets the default type and name options for all following metadata requests.
Arguments:
elem Element
The element containing the metadata to be extracted.
options (Optional) Options
A set of key/value pairs that define the type of metadata to be extracted. All options are optional. See the metadata plugin page for more information.
Examples:
* Code
Setup metadata plugin to look for a custom attribute.
<li class="someclass {some:'random', json: 'data'}">...</li>
<script>
$('li.someclass').each(function(){
var data = $.metadata.get(this);
alert(data.some);
});
</script>
分享到:
- 2009-03-16 12:24
- 浏览 3501
- 评论(0)
- 论坛回复 / 浏览 (0 / 12059)
- 查看更多
相关推荐
jquery.metadata.2.0.zip jquery metadata插件
在其他的网站好不容易才找到的jQuery Metadata模块2.0版本源代码
使用class="{}"的方式,必须引入包:jquery.metadata.js 可以使用如下的方法,修改提示内容: class="{required:true,minlength:5,messages:{required:'请输入内容'}}" 在使用equalTo关键字时,后面的内容必须加上...
jquery.validate.js jquery.metadata.js jquery.autocomplete.js的打包合集,这些jquery的扩展包非常好用,希望对需要的童鞋有用
在其他的网站好不容易才找到的jQuery Metadata模块1.0版本源代码
jquery validate用于前台验证,里面的remote异步验证,jquery.metadata.js加载后可以直接在控件旁写class{}
jquery.metadata.2.1.js
jquery.metadata.js下载
jQuery插件——jQuery.metadata.js
jquery.metadata.js
Jquery+Jquery.metadata.js 的验证方式,这种验证方式可减少代码量,并且重用性高,因为有部分验证的代码是封装好的我们直接拿来用就可以了
juery.metadata.js,jquery表单验证插件
页面,表单校验必备js文件,如注册,登录界面
jq和jq validate 的相关js库。
165-Metadata Service 架构详解1
jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求。该插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证,同时提供了一个用来...
再后面就简单了:neutron-ns-metadata-proxy 将请求通过 unix domain socket 发给 neutron-metadata-a
jquery.metadata.js是一个支持固定格式解析的jquery插件,结合Validation插件能很好地融合到验证规则编码中~
提供jquery验证插件的专用js文件,包括jquery.js、jquery.validation.js、jquery.metadata.js,满足使用jquery-validate插件的需求