来自javascript图像的多个源代码
我正在尝试使用javascript获取网页上3幅图像的源代码。 现在。。第一个图像源我可以得到,但其他两个给我不能读取空错误的src 这是我的密码:来自javascript图像的多个源代码,javascript,jquery,tampermonkey,Javascript,Jquery,Tampermonkey,我正在尝试使用javascript获取网页上3幅图像的源代码。 现在。。第一个图像源我可以得到,但其他两个给我不能读取空错误的src 这是我的密码: var a = document.querySelector("#cimg1 > img").src; var b = document.querySelector("#cimg2 > img").src; var c = document.querySelector("#cimg3 > img").src; alert(Str
var a = document.querySelector("#cimg1 > img").src;
var b = document.querySelector("#cimg2 > img").src;
var c = document.querySelector("#cimg3 > img").src;
alert(String(a+b+c));
HTML:
您需要检查Dom内容是否已加载为@chazsolo指出的内容。您正在查找页面上存在的图像src。如果您使用的是jquery,那么您必须将代码封装在如下函数中
$(function(){
//... put your code here....
});
如果你喜欢,那么你可以做一些像
document.addEventListener('DOMContentLoaded', function(){
//... put your code here....
});
您的代码对我来说运行良好,请检查是否存在任何控制台错误UserScript.html?id=b93dc5b0-9091-4e94-940c-918e8351bc1e:4错误:执行脚本“MrSebasAutoCaptcha”失败!无法读取Null的属性“src”我可以通过邮件或discord与您联系吗?代码适用于原始html,但在网站上尝试运行时不起作用您是否要等到DOM就绪后再查询图像?