这是我正在尝试做的事情:
目前我正在使用它来创建一个与.cookie类名匹配的所有元素的数组.现在我得到该元素的文本值,这不是我需要的:
var getAllCookies = $('.cookie').text();
var cookiesArray = jQuery.makeArray(getAllCookies);
alert(cookiesArray[0]);
我需要的是找到某个类的所有元素(.cookie),获取该元素的ID值并将该ID值存储在数组中.
解决方法
我认为这应该做你想要的事情:
var ids = $('.cookie').map(function(index) {
// this callback function will be called once for each matching element
return this.id;
});
Documentation for map.
Here’s a working jsFiddle demo.