jQuery:计数图像 [英] jQuery: Count images
本文介绍了jQuery:计数图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为example_**_title.jpg
的图像的文件夹.
I have a folder with images named example_**_title.jpg
.
我想用jQuery/Javascript计算这些图像并返回图像数.
I want to count these images with jQuery/Javascript and return the number of images.
我尝试过:
count = 0;
for (var i=0; i<=10; i++){
var bg_url = 'http://www.example-url.com/example_'+i+'_title.jpg';
$.get(bg_url)
.done(function(){
count++;
})
.fail(function(){
});
}
alert(count);
感谢您的帮助.
琼斯
推荐答案
由于您不想get
文件,只是想计数,因此可以使用type:'HEAD'
,它应该减少数据量:
Since you don't want to get
the files but just count, you can use type:'HEAD'
It should reduce the amount of data :
$.ajax({
url:'http://www.example-url.com/example_'+i+'_title.jpg',
type:'HEAD',
error: function()
{
//file doesn't exist
},
success: function()
{
count++;
}
});
这篇关于jQuery:计数图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文