Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取背景图像url值_Javascript_Html_Url_Background Image - Fatal编程技术网

Javascript 获取背景图像url值

Javascript 获取背景图像url值,javascript,html,url,background-image,Javascript,Html,Url,Background Image,我有7个div,每个div有一个不同的背景图像,我需要在html中内联传递每个背景图像的url,有人能帮我吗 我尝试过不同的方法,但没有成功:( 使用.each循环浏览所有div,以获取背景图像 $("div").each( function(index) { var thisUrl = $(this).css("backgroundImage"); var content = $("p").html(); // current content

我有7个div,每个div有一个不同的背景图像,我需要在html中内联传递每个背景图像的url,有人能帮我吗

我尝试过不同的方法,但没有成功:(

使用.each循环浏览所有div,以获取背景图像

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

请发布您拥有的代码和您尝试过的内容。请将您尝试过的HTML代码做成一个JSFIDLE。还请解释您想用它做什么。将以
url('path/to/image')
格式返回。您可能想提一下这是在使用jQuery,因为问题没有用它标记。