展开全部
Html代码
1.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2.<html xmlns="http://www.w3.org/1999/xhtml">
3.<head>
4.<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5.<title></title>
6.<script type="text/javascript" src="jquery.metadata.2.0/jquery.metadata.2.0/test/jquery.js"></script>
7.<!-- 这里既引用了1.0又引用了2.0,就是为了说明它们之间没有冲突,我的理解是以前的优秀插件里面使用了1.0,但是1.0的问题确实有,所以2.0把meta改成metadata 这样就不会相互冲突了-->
8.<script type="text/javascript" src="jquery.metadata.2.0/jquery.metadata.2.0/jquery.metadata.js"></script>
9.<script type="text/javascript" src="jquery.metadata.1.0/jquery.metadata.1.0/jquery.metadata.js"></script>
10.<script language="javascript">
11. $(document).ready(function(){
12. alert($(".media").metadata().src);
13. alert($('li.someclass').metadata().some);
14. });
15.
16.</script>
17.</head>
18.
19.<body>
20.
21.<OBJECT class="media {src:'/tems/upload/192168.mp3'}" data="[object Object]"></OBJECT>
22.<li class="someclass {some: 'data'} anotherclass">...</li>
23.OR
24.<li data="{some:'random', json: 'data'}">...</li>
25.OR
26.<li><script type="data">{some:"json",data:true}</script> ...</li>
27.<script language="javascript">
28.var data = $('li.someclass').metadata();
29.if ( data.some && data.some == 'data' )
30. alert('It Worked!');
31.</script>
32.</body>
33.</html>
<!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.
Javascript代码
1.$(".selector").metadata({
2. type: 'attr'
3.})
$(".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'.
Javascript代码
1.$(".selector").metadata({
2. type: 'attr',
3. name: 'jdata'
4.})
$(".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.
Javascript代码
1.$(".selector").metadata({
2. single: 'jdata'
3.})
$(".selector").metadata({
single: 'jdata'
})
Examples:
Gets metadata from the class attribute.
Javascript代码
1.<li class="someclass {some: 'data'} anotherclass">...</li>
2.
3.<script>alert($('li.someclass').metadata().some);</script>
<li class="someclass {some: 'data'} anotherclass">...</li>
<script>alert($('li.someclass').metadata().some);</script>
Gets metadata from a custom attribute.
Javascript代码
1.<li data="{some:'random', json: 'data'}">...</li>
2.<script>alert($('li.someclass').metadata({type:'attr',name:'data'}).some);</script>
<li data="{some:'random', json: 'data'}">...</li>
<script>alert($('li.someclass').metadata({type:'attr',name:'data'}).some);</script>
Gets metadata from a child element.
Javascript代码
1.<li class="someclass"><script type="application/json">{some:"json",data:true}</script>...</li>
2.<script>alert($('li.someclass').metadata({type:'elem',name:'script'}).some);</script>
<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.
Javascript代码
1.<li data="{some:'random', json: 'data'}" class="someclass">...</li>
2.
3.<script>
4.$.metadata.setType('attr','data');
5.alert($('li.someclass').metadata().some);
6.</script>
<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.
Javascript代码
1.<li class="someclass {some:'random', json: 'data'}">...</li>
2.
3.<script>
4.$('li.someclass').each(function(){
5. var data = $.metadata.get(this);
6. alert(data.some);
7.});
8.</script>
<li class="someclass {some:'random', json: 'data'}">...</li>
<script>
$('li.someclass').each(function(){
var data = $.metadata.get(this);
alert(data.some);
});
</script>
1.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2.<html xmlns="http://www.w3.org/1999/xhtml">
3.<head>
4.<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5.<title></title>
6.<script type="text/javascript" src="jquery.metadata.2.0/jquery.metadata.2.0/test/jquery.js"></script>
7.<!-- 这里既引用了1.0又引用了2.0,就是为了说明它们之间没有冲突,我的理解是以前的优秀插件里面使用了1.0,但是1.0的问题确实有,所以2.0把meta改成metadata 这样就不会相互冲突了-->
8.<script type="text/javascript" src="jquery.metadata.2.0/jquery.metadata.2.0/jquery.metadata.js"></script>
9.<script type="text/javascript" src="jquery.metadata.1.0/jquery.metadata.1.0/jquery.metadata.js"></script>
10.<script language="javascript">
11. $(document).ready(function(){
12. alert($(".media").metadata().src);
13. alert($('li.someclass').metadata().some);
14. });
15.
16.</script>
17.</head>
18.
19.<body>
20.
21.<OBJECT class="media {src:'/tems/upload/192168.mp3'}" data="[object Object]"></OBJECT>
22.<li class="someclass {some: 'data'} anotherclass">...</li>
23.OR
24.<li data="{some:'random', json: 'data'}">...</li>
25.OR
26.<li><script type="data">{some:"json",data:true}</script> ...</li>
27.<script language="javascript">
28.var data = $('li.someclass').metadata();
29.if ( data.some && data.some == 'data' )
30. alert('It Worked!');
31.</script>
32.</body>
33.</html>
<!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.
Javascript代码
1.$(".selector").metadata({
2. type: 'attr'
3.})
$(".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'.
Javascript代码
1.$(".selector").metadata({
2. type: 'attr',
3. name: 'jdata'
4.})
$(".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.
Javascript代码
1.$(".selector").metadata({
2. single: 'jdata'
3.})
$(".selector").metadata({
single: 'jdata'
})
Examples:
Gets metadata from the class attribute.
Javascript代码
1.<li class="someclass {some: 'data'} anotherclass">...</li>
2.
3.<script>alert($('li.someclass').metadata().some);</script>
<li class="someclass {some: 'data'} anotherclass">...</li>
<script>alert($('li.someclass').metadata().some);</script>
Gets metadata from a custom attribute.
Javascript代码
1.<li data="{some:'random', json: 'data'}">...</li>
2.<script>alert($('li.someclass').metadata({type:'attr',name:'data'}).some);</script>
<li data="{some:'random', json: 'data'}">...</li>
<script>alert($('li.someclass').metadata({type:'attr',name:'data'}).some);</script>
Gets metadata from a child element.
Javascript代码
1.<li class="someclass"><script type="application/json">{some:"json",data:true}</script>...</li>
2.<script>alert($('li.someclass').metadata({type:'elem',name:'script'}).some);</script>
<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.
Javascript代码
1.<li data="{some:'random', json: 'data'}" class="someclass">...</li>
2.
3.<script>
4.$.metadata.setType('attr','data');
5.alert($('li.someclass').metadata().some);
6.</script>
<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.
Javascript代码
1.<li class="someclass {some:'random', json: 'data'}">...</li>
2.
3.<script>
4.$('li.someclass').each(function(){
5. var data = $.metadata.get(this);
6. alert(data.some);
7.});
8.</script>
<li class="someclass {some:'random', json: 'data'}">...</li>
<script>
$('li.someclass').each(function(){
var data = $.metadata.get(this);
alert(data.some);
});
</script>
展开全部
表单验证
代码 metadata-demo.html
view plaincopy to clipboardprint?
<!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>
<!--
<mce:script type="text/javascript" src="jquery.js" mce_src="jquery.js"></mce:script>
<mce:script type="text/javascript" src="../jquery.metadata.js" mce_src="jquery.metadata.js"></mce:script>
-->
<mce:script src="http://code.jquery.com/jquery-latest.js" mce_src="http://code.jquery.com/jquery-latest.js"></mce:script>
<mce:script type="text/javascript"src="http://jquery.bassistance.de/validate/lib/jquery.metadata.js"></mce:script>
<mce:script language="javascript"><!--
$(function() {
alert( $("#liangO").metadata().some ); // data
/*
alert( $("#item1" ).metadata().item_id ); // 1
alert( $("#item1" ).metadata({type: "class"})
.item_id ); // 1
*/
alert( $("#item2" ).metadata({"type": "attr"})
.item_label
); // "Label"
alert( $("#item2" ).metadata({"type": "attr",
"name": "metadata"})
.item_label ); // "Label"
/*
alert( $("#item3" ).metadata({"type": "elem"})
.item_label ); // FF下为"Label",IE下为undefined
alert( $("#item3" ).metadata({"type": "elem",
"name": "metadata"})
.item_label ); // FF下为"Label",IE下为undefined
alert( $("#item4" ).metadata({"type": "elem",
"name": "script"})
.item_label ); // "Label"
*/
});
// --></mce:script>
</head>
<body>
<ol>
<li id="liangO" class="someclass {some: 'data'} anotherclass">...</li>
<li id="item1" class="someclass {'item_id': 1, item_label: 'Label'}">Item 1</li>
<li id="item2" metadata='{"item_id": 1, "item_label": "Label"}'>Item 2</li>
<li id="item3">
<metadata style="display: none;" mce_style="display: none;">{item_id: 1, item_label: 'Label'}</metadata>
Item 3 </li>
<li id="item4">
<mce:script type="metadata"><!--
{"item_id": 1, "item_label": "Label"}
// --></mce:script>
Item 4 </li>
</ol>
</body>
</html>
代码 metadata-demo.html
view plaincopy to clipboardprint?
<!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>
<!--
<mce:script type="text/javascript" src="jquery.js" mce_src="jquery.js"></mce:script>
<mce:script type="text/javascript" src="../jquery.metadata.js" mce_src="jquery.metadata.js"></mce:script>
-->
<mce:script src="http://code.jquery.com/jquery-latest.js" mce_src="http://code.jquery.com/jquery-latest.js"></mce:script>
<mce:script type="text/javascript"src="http://jquery.bassistance.de/validate/lib/jquery.metadata.js"></mce:script>
<mce:script language="javascript"><!--
$(function() {
alert( $("#liangO").metadata().some ); // data
/*
alert( $("#item1" ).metadata().item_id ); // 1
alert( $("#item1" ).metadata({type: "class"})
.item_id ); // 1
*/
alert( $("#item2" ).metadata({"type": "attr"})
.item_label
); // "Label"
alert( $("#item2" ).metadata({"type": "attr",
"name": "metadata"})
.item_label ); // "Label"
/*
alert( $("#item3" ).metadata({"type": "elem"})
.item_label ); // FF下为"Label",IE下为undefined
alert( $("#item3" ).metadata({"type": "elem",
"name": "metadata"})
.item_label ); // FF下为"Label",IE下为undefined
alert( $("#item4" ).metadata({"type": "elem",
"name": "script"})
.item_label ); // "Label"
*/
});
// --></mce:script>
</head>
<body>
<ol>
<li id="liangO" class="someclass {some: 'data'} anotherclass">...</li>
<li id="item1" class="someclass {'item_id': 1, item_label: 'Label'}">Item 1</li>
<li id="item2" metadata='{"item_id": 1, "item_label": "Label"}'>Item 2</li>
<li id="item3">
<metadata style="display: none;" mce_style="display: none;">{item_id: 1, item_label: 'Label'}</metadata>
Item 3 </li>
<li id="item4">
<mce:script type="metadata"><!--
{"item_id": 1, "item_label": "Label"}
// --></mce:script>
Item 4 </li>
</ol>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询