简体   繁体   English

获取背景图片网址值

[英]Get background-image url value

I have 7 divs each one with a different background-image and I need to get the url of each background image passed inline in the html, can someone help me with that? 我有7个div,每个div具有不同的背景图像,我需要获取在html中内联传递的每个背景图像的url,有人可以帮我吗?

I've tried different ways but with no success :( 我尝试了不同的方法,但没有成功:(

http://jsfiddle.net/e46bf/ http://jsfiddle.net/e46bf/

use .each to cycle through all the div, to get background images. 使用.each循环遍历所有div,以获得背景图像。

$("div").each(
    function(index) {
        var thisUrl = $(this).css("backgroundImage");
        var content = $("p").html(); // current content
        $("p").html(content+" "+thisUrl);
    }
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM