在页面中有很多class 为survey的div,我想得到现在显示的survey是所有survey中的index。 所以
var showed =$('.survey').filter(function(){
return $(this).css("display") == "block";
});
var index = $(".survey").map(function(){return this.id}).indexOf(showed.first().id);
报错没有indexOf方法,因为$(".survey").map(function(){return this.id})
是一个object [object object]。
请大家帮忙看一下啊,谢谢了。为什么map返回不是array?
因为 jQuery 返回的是 jQuery 对象。你需要调用它的
.get()
方法。参见 jQuery 的 .map() 的文档。