[英]javascript how do i find which elements contain a background image using the style attribute
I am trying to add script to a web page that is generated as part of a go-daddy web site. 我试图将脚本添加到作为Go-Daddy网站的一部分生成的网页中。
The image is presented in a div as a background image that was set using the style attribute. 该图像以div形式显示为使用style属性设置的背景图像。
style="background-image: url("//img1.wsimg.com/isteam/ip/c77f0810-0ea1-4425-b963-0e5820c70a3f/5a18a70f-82dc-45b6-bfb8-8f8e7ff1c875.jpg/:/cr=t:0%25,l:0%25,w:100%25,h:100%25/rs=w:1400,h:400,cg:true,m/cr=w:1400,h:400,ax:c,ay:c");"
The id of the div container is generated automatically and changes between runs. div容器的ID是自动生成的,并且在运行之间会更改。
Is there anyway I can find the elements on the page that have a background image set in the HTML style attribute using plain javascript ? 无论如何,我可以使用普通的javascript在页面上找到在HTML样式属性中设置了背景图片的元素吗?
Try this: 尝试这个:
var elements = document.body.getElementsByTagName("*")
for (var i = 0 ; i < elements.length ; i++) {
if (elements[i].style.backgroundImage) {
// DO SOMETHING HERE
alert(elements[i].id + " has background image")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.