简易模拟3.1JQ的$().data方法
标签:
JavaScript
<head>
<script>
$(document).ready(function(){
var test=function(){
var global=Math.random();
var uid=1;
function data(){
this.ex=global+uid++;
}
var pri=new data();
var user=new data();
return function (a,b,c){
if(c!=undefined){
a[user.ex]=a[user.ex]||{};
a[user.ex][b]=c;
}else{
return a[user.ex][b];
}
}
}();
var wwb=document.getElementById("123");
var hua=document.getElementById("234");
test(wwb,"name","wangwenbo");
test(wwb,"name1","wangwenbo1");
test(wwb,"name2","wangwenbo2");
test(hua,"name","hualing");
test(hua,"name1","hualing1");
test(hua,"name2","hualing2");
console.log($(wwb));
console.log(test(wwb,"name1"));
console.log(test(hua,"name2"));
});
</script>
</head>
<body>
<p id="123">如果你点我,我就会消失。</p>
<p id="234">继续点我!</p>
<p id="456">接着点我!</p>
</body>
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦