就像我在标题中所写的那样,我有多个具有相同类的元素,我获取该类并尝试检查该图像的子图像的宽度/高度/src。
我只能获取第一个图像的高度//宽度,但是我获取了所有图像的 src。
这是 html:
<a class="test">
<img src="http://www.kitchenspro.com/files/Testimonials/Large/1502046700250312a71707.jpg">
</a>
<a class="test">
<img src="http://www.kitchenspro.com/files/Testimonials/Large/40183.9461166782.jpg">
</a>
<a class="test">
<img src="http://sphotos-a.xx.fbcdn.net/hphotos-ash4/s480x480/391362_365319466870994_1543740404_n.jpg">
</a>
这是jquery
var imagesrc= "";
var imageheight = "";
var imagewidth = "";
var i=0;
$(".test > img").each(function() {
i++;
imagesrc = $(this).attr("src");
imageheight = $(this).width();
imagewidth = $(this).height();
document.write("<br>This is image's src: " + imagesrc + " This is img height: " + imageheight + " this is width: " + imagewidth + "<br>");
});
如果我没有以正确的方式提供代码,我深表歉意。
任何帮助将不胜感激。
提前致谢。
最佳答案
第一次调用 document.write
会破坏其余元素,因此您只能从其中一个元素获取信息,使用 .append() 或其他方法来显示结果。
关于javascript - 图像高度只会从大量图像中检索一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11514358/