这是我在javascript中的情况:
EA = {
DOMElement: $('#example img'),
photos: '',
...
countSelected: function(){
var len = 0;
var id = '';
EA.DOMElement.each(function(index){
id = $(this).attr('data-id');
EA.photos += id + ",";
});
len = EA.photos.length;
return len;
},
}
函数 countSelected 返回 0 但如果我使用这个解决方案一切正常:
countSelected: function(){
var len = 0;
var id = '';
$('#example img').each(function(index){
id = $(this).attr('data-id');
EA.photos += id + ",";
});
len = EA.photos.length;
return len;
},
在我看来,问题出在选择器上:$(this)。你知道有什么解决办法吗?
谢谢!