[英]Get img src from a cell Javascript
I want to take the src
of an image of out every cell from a table's tr
. 我想从表的
tr
每个单元格的图像的src
。
Here's what I am trying to do: 这是我想做的事情:
function returnPics(){
var x = document.getElementById("table2").rows[0].cells.length;
for (var i=0 ; i <x ; i++){
console.log("in");
var link = document.getElementById("table2").rows[0].cells[i].childNodes[i].src ;
console.log(link);
}
}
I have also tried the getAttribute
method: 我也尝试过
getAttribute
方法:
var link = document.getElementById("table2").rows[0].cells[i].getAttribute("src")
If you use jQuery it is really simple. 如果您使用jQuery,则非常简单。
$('#table2 img').each(function() {
var link=$(this).attr('src');
console.log(link);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.