Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 了解特定文件夹的总图像宽度_Jquery - Fatal编程技术网

Jquery 了解特定文件夹的总图像宽度

Jquery 了解特定文件夹的总图像宽度,jquery,Jquery,我有两个文件夹中的图像。一个在tne命名文件夹中,另一个在two命名文件夹中 /images/one/one.jpg /images/one/two.jpg /images/one/any.jpg and more.... /images/two/any.jpg /images/two/what.jpg /images/two/ever.jpg /images/two/images.jpg and more.... 这些图像都在一个分区中,就像这样 <div id="test">

我有两个文件夹中的图像。一个在
tne
命名文件夹中,另一个在
two
命名文件夹中

/images/one/one.jpg
/images/one/two.jpg
/images/one/any.jpg
and more....


/images/two/any.jpg
/images/two/what.jpg
/images/two/ever.jpg
/images/two/images.jpg
and more....
这些图像都在一个分区中,就像这样

<div id="test">
<img src="/images/one/...." />
<img src="/images/one/...." />
<img src="/images/two/...." />
<img src="/images/two/...." />
</div>

问题:

现在我想知道名为
one
的第一个文件夹的总图像宽度,以及名为
two的第二个文件夹的总图像宽度

使用jquery可以吗?

试试以下方法:

var totalImagesFolderOne = 0;

$("div#test > img[src*='/images/one/']").each(function(){
  totalImagesFolderOne += $(this).width();
});

alert("Total width images in folder `one`: " + totalImagesFolderOne);
这里有一个

试试这个:

var totalImagesFolderOne = 0;

$("div#test > img[src*='/images/one/']").each(function(){
  totalImagesFolderOne += $(this).width();
});

alert("Total width images in folder `one`: " + totalImagesFolderOne);
这里有一个可以在jquery中使用
wrapAll()
函数:

var allWidth = $('#test img').wrapAll('<span>').parent().width();
var oneWidth = $imgOne.wrapAll('<span>').parent().width();
var $imgOne = $("div#test img[src*='/images/one/']");
$('#test img').unwrap();
$imgOne.unwrap();

console.log(oneWidth) //one images width
console.log(allWidth - oneWidth) //two images width.
var allWidth=$('#test img').wrapAll(''.parent().width();
var oneWidth=$imgOne.wrapAll(“”).parent().width();
var$imgOne=$(“div#testimg[src*='/images/one/']);
$(“#测试img”).unwrap();
$imgOne.unwrap();
console.log(oneWidth)//一个图像宽度
log(allWidth-oneWidth)//两个图像的宽度。
您可以在jquery中使用
wrapAll()
函数:

var allWidth = $('#test img').wrapAll('<span>').parent().width();
var oneWidth = $imgOne.wrapAll('<span>').parent().width();
var $imgOne = $("div#test img[src*='/images/one/']");
$('#test img').unwrap();
$imgOne.unwrap();

console.log(oneWidth) //one images width
console.log(allWidth - oneWidth) //two images width.
var allWidth=$('#test img').wrapAll(''.parent().width();
var oneWidth=$imgOne.wrapAll(“”).parent().width();
var$imgOne=$(“div#testimg[src*='/images/one/']);
$(“#测试img”).unwrap();
$imgOne.unwrap();
console.log(oneWidth)//一个图像宽度
log(allWidth-oneWidth)//两个图像的宽度。

这应该能帮到你:

$(文档).ready(函数(){
var dirs=['sports','cats'];
var widths=[0,0];//索引0是文件夹1中图像的宽度,索引1是文件夹2中图像的宽度
对于(变量i=0;i=0)
{
宽度[i]=宽度[i]+$(this.width();
}
});
}
警报('总宽度1:'+widths[0]+',总宽度2:'+widths[1]);
});
它稍微高级一点,但无需花费太多时间即可扩展,只需将更多元素插入前两个数组即可

编辑
忘了提到“运动”和“猫”当然只是示例文件夹。在您的情况下,您需要输入“image/one”和“image/two”。这也使用了很少的jQuery,因为在这种情况下它实际上不是必需的。

这应该可以帮到您:

$(文档).ready(函数(){
var dirs=['sports','cats'];
var widths=[0,0];//索引0是文件夹1中图像的宽度,索引1是文件夹2中图像的宽度
对于(变量i=0;i=0)
{
宽度[i]=宽度[i]+$(this.width();
}
});
}
警报('总宽度1:'+widths[0]+',总宽度2:'+widths[1]);
});
它稍微高级一点,但无需花费太多时间即可扩展,只需将更多元素插入前两个数组即可

编辑
忘了提到“运动”和“猫”当然只是示例文件夹。在您的情况下,您需要输入“image/one”和“image/two”。这也使用很少的jQuery,因为在这种情况下它不是必须的。

如果你可以访问文件夹,你可以通过获取每个图像来迭代,并通过
new image()查看其维度。
google+“php get image size”编辑还是在客户端?我们怎么知道?@Virus721 jQuery没有服务器端版本(据我所知),而且?这并不意味着作者理解jQuery只是客户端。仅供参考phpquery@c-链接,我的评论只有在您知道图像的文件名时才有效。如果您可以访问文件夹,您可以通过获取每个图像进行迭代,并通过
new image()
google+“php get image size”编辑查看其维度,还是在客户端?我们怎么知道?@Virus721 jQuery没有服务器端版本(据我所知),而且?这并不意味着作者理解jQuery只是客户端。仅供参考phpquery@c-链接,我的评论只有在你知道图片的文件名时才有效。