//但是我无法真正获取ID并将其分配给不在范围内的数组?(或者我可以)
是的你可以!
var IDs = [];$("#mydiv").find("span").each(function(){ IDs.push(this.id); });请注意,当您处于正确的轨道上时,Sighohwell和cletus都指出了使用属性过滤器(将匹配的元素限制为具有ID的元素)和jQuery的内置
map()函数来完成此任务的更可靠,更简洁的方法:
var IDs = $("#mydiv span[id]") // find spans with ID attribute .map(function() { return this.id; }) // convert to set of IDs .get(); // convert to instance of Array (optional)


