图像带回了无效的JS

时间:2016-03-01 08:03:27

标签: javascript html

我正在尝试从DOM捕获此链接中的图像,但我不断获取null。 请帮助:: The site is aliexpress.com

这是我的代码;

t.image = document.querySelector('.item-group tbody a img').getAttribute("src");

DOM:

The DOM

非常感谢您的帮助。感谢。

1 个答案:

答案 0 :(得分:-1)

假设querySelector返回正确的元素(在控制台中写入并检查它是否真的找到了img标签),你需要用src替换get getAttribute("src");,所以它看起来像这样:

t.image = document.querySelector('.item-group tbody a img').src;