清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <!DOCTYPE HTML> < html > < head > < meta charset = "utf-8" > < title >jquery操作HTML5 的data-*的用法</ title > </ head > < script src = "http://code.jquery.com/jquery-2.1.0.min.js" ></ script > < script > $(function(){ //读取data-*的值 $("li").each(function(v) { console.log($(this).data('name')); }); //设置data-*的值 $("li").eq(0).data('name','bryant'); $("li").each(function(v) { console.log($(this).data('name')); }); //删除data-*的值 这里使用的是removeAttr,测试官方的removeData是不起作用的 $("li").eq(0).removeAttr('data-name'); $("li").each(function(v) { console.log($(this).data('name')); }); }) </ script > < body > < ul > < li data-name = "kobe" >科比</ li > < li data-name = "gasol" >加索尔</ li > < li data-name = "nash" >纳什</ li > < li data-name = "fisher" >费舍尔</ li > </ ul > </ body > </ html > |