我有三个 div,如下所示。
<div id="div#product_img_wrapper">
<div id="product_design1" class="timage" style="z-index: 20; background-image: url('');"></div>
<div id="product_design2" class="timage" style="z-index: 20; background-image: url('');"></div>
<div id="product_design3" class="timage" style="z-index: 20; background-image: url('');"></div>
</div>
我使用下面的 jquery 函数在 div 上方循环槽,如下所示。
jQuery('div#product_img_wrapper div').each(function(){
var background = jQuery(this).css('background-image').replace('url(','').replace(')','');
if(background != 'none')
{
console.log(jQuery(this));
console.log(background);
}
});
输出
"http://localhost/project/index.php?option=com_project&controller=project&task=project&method=1"
"http://localhost/project/index.php?option=com_project&controller=project&task=project&method=1"
"http://localhost/project/index.php?option=com_project&controller=project&task=project&method=1"
我要做的是获取每个 div 的 background-image 属性。但它返回我这个浏览器显示的 URL?上面的代码有什么问题?为什么 jQuery(this).css('background-image') 返回浏览器 URL?