![](/img/trans.png)
[英]What is the best way in jQuery to wrap elements based on its data attribute?
[英]In JQuery, what's the best way to get a data attribute of a set of nodes into an array?
在JQuery中,将一组节点的数据属性放入数组的最佳方法是什么?
我使这种语法工作:
var ids = $("a.some_class").map(function(index, item) {return item.getAttribute('data-id');});
有没有更简单的语法呢?
谢谢
尝试
var ids = $("a.some_class").map(function() {
return $(this).data('id'); //or return this.getAttribute('data-id');
}).get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.