jquery上传多张图片
发布时间: 2025-07-08 04:26:44
1. jquery 点击一次加载几张图片,再点击再加载几张图片,一直到所有图片都显示,怎么实现
varimgMana=function(){
//内部指针索引
this.idx=0;
//需要加载的图片列表
this.imgs=[
'https://dimg04.c-ctrip.com/images/70010b0000005a2k71535_280_170_112.jpg',
'https://dimg04.c-ctrip.com/images/700f0c0000006nxnfD731_280_170_112.jpg',
'https://dimg04.c-ctrip.com/images/70020h0000008s9xx8ACF_280_170_112.jpg',
'https://dimg04.c-ctrip.com/images/700j0h0000008sx877A9B_280_170_112.jpg',
'https://dimg04.c-ctrip.com/images/700u0h0000008zdvbA836_1920_360_111.jpg'
];
//加载图片num:加载的数量
this.loadImg=function(num){
num=num||1;
varinfo,len=this.idx+num;
for(this.idx;this.idx<len;this.idx++){
info=this.imgs[this.idx];
if(!info){
alert('图片都加载完啦');
returnthis;
}
this.render(info);
}
}
//渲染图片
this.render=function(img){
img&&$('body').append("<imgsrc='"+img+"'/>");
}
returnthis;
}
//使用方式
varimgM=newimgMana();
$('.button').click(function(){
imgM.loadImg(2);
});
热点内容