【发布时间】:2015-02-06 04:34:47
【问题描述】:
html 对象:
<div data-myAttribute="test"></div>
代码:
var $o = $("div");
$.each($o.data(),function(k,v){
console.log(k);
//writes 'myattribute' instead of 'myAttribute'
});
如何保留属性的大小写?
【问题讨论】:
-
你应该使用
data-my-attribute来获取.data('myAttribute') -
看看here
-
@A.Wolff 谢谢,这似乎对我有所帮助。尽管根据答案,它不能使用。
-
@ControlFreak
data-my-attribute是关于规范的完全有效的属性名称:For each name on the list, for each U+002D HYPHEN-MINUS character (-) in the name that is followed by a character in the range U+0061 to U+007A (U+0061 LATIN SMALL LETTER A to U+007A LATIN SMALL LETTER Z), remove the U+002D HYPHEN-MINUS character (-) and replace the character that followed it by the same character converted to ASCII uppercase. -
@A.Wolff 我会把你的 cmets 作为答案,因为它回答了 OP 的意图(并且也符合我想要的)
标签: jquery html custom-data-attribute jquery-data