从 img 标签中获取 src 值 [英] Get the src value from the img tag
本文介绍了从 img 标签中获取 src 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 JavaScript 文件中编写了此代码部分,以选择 .html
文件中的所有 img
标记.
I wrote this code part in my JavaScript file to select all img
tags in my .html
file.
var imgs = document.getElementsByTagName('img');
如何将这些标签的 src
值提取到数组中以备将来使用?
How can I extract the src
values of those tags to an array for future use?
推荐答案
就这样试试
function img_find() {
var imgs = document.getElementsByTagName("img");
var imgSrcs = [];
for (var i = 0; i < imgs.length; i++) {
imgSrcs.push(imgs[i].src);
}
return imgSrcs;
}
这篇关于从 img 标签中获取 src 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文