<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<title></title>
</head>
<body>
<div id="aaron">缓存接口测试</div></br>
<script type="text/javascript">
var ele1 = $("#aaron");
var ele2 = $("#aaron");
ele1.data('a',1111);
ele2.data('a',2222);
show('第一组,通过$().data()的方式,只取到最后一个a值,之前的被覆盖')
show(ele1.data('a'))
show(ele2.data('a'))
show()
//=======第二组=========
show('第二组,通过$.data的方式,取到2组b值,未覆盖')
$.data(ele1,"b","1111")
$.data(ele2,"b","2222")
show($.data(ele1,"b"))
show($.data(ele2,"b") )
function show(data) {
if (arguments.length == 2) {
var info = arguments[0]
var data = arguments[1];
for (var key in data) {
$("body").append('<li>' + info +'key->' + key + '; value->' + data[key] + '</li>')
}
return
}
if (!data) {
return $("body").append('</br>')
}
if (typeof data === 'object') {
for (var key in data) {
$("body").append('<li>key->' + key + '; value->' + data[key] + '</li>')
}
} else {
$("body").append('<li>' + data + '</li>')
}
}
</script>
</body>
</html>