jQuery设置数据属性 [英] jquery set data attr
本文介绍了jQuery设置数据属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML
<div id="you" data-you="Hello mean">super</div>
是#you html元素更改data-you属性
is #you html element change data-you attribute
console.log($("#you").data("you")); // Hello mean
$("#you").attr("data-you", "yes change you atribute");
console.log($("#you").data("you")); // Hello mean | does not change.
属性"data-you"在我更改时不会更改.我该怎么办?
Attribute "data-you" does not change when I change. How can I do this?
谢谢.
推荐答案
attr()而且您不必更改data()方法.
attr() And you can not have to change the data() method.
尝试以下方式:
console.log($("#you").data("you")); // Hello mean
$("#you").data("you", "yes change you atribute"); // yes change you atribute
console.log($("#you").data("you")); // yes change you atribute
数据示例 http://api.jquery.com/data/
这篇关于jQuery设置数据属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文