继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

简易模拟3.1JQ的$().data方法

甜酒0917
关注TA
已关注
手记 13
粉丝 2
获赞 23
<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>
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP