我有一个小问题,在无序列表中创建列表项目中的对象。我创建一个画廊,我需要为每个画廊缩略图,它是自己的对象,所以我遍历每个列表项使用jQuery的$ .each()从列表元素创建javascript对象
问题是我不知道如何给每个对象/它是它自己的实例名称。
下面的代码:
function galleryButton(){
this.link
this.name
this.image
this.identifier,
this.goPage = function(){
$('.container').animate({opacity : '0'}, 500).load(this.link + ' .galContainer', function(){$('.container').animate({opacity : '1'})});
return false;
}
}
$(document).ready(function(){
$.ajaxSetup({
cache:false
});
$('.gallery li a').each(function(node, value){
this = new galleryButton();
this.link = $(this).attr('href');
this.name = $(this).attr('name');
this.image = $(this + " img").attr('src');
this.identifier = $(this).attr('data-pic-id');
$(this).click(this.goPage);
})
$('.goback').click(function(){
var back = $(this).attr('href');
$('.container').animate({opacity : '0'}, 500).load(back + ' .gallery', function(){$('.container').animate({opacity : '1'})});
return false;
});
});
你不能指定['this'关键字](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this)!!! – Bergi