0

我目前正在使用此功能添加到 posternew imgframe div 的样式属性:

$(function () { $('.posternew .imgframe').each(function () { 
    $(this).attr("style", $(this).attr("style").replace("background:", ""));
    $(this).attr('style', 'background:url(images/new.png),' + $(this).attr('style')); 
    });  
});

这在 Chrome 和 Firefox 中完美运行,但在 IE 9 或 10 下不起作用。我尝试对其进行稍微不同的格式化,但无济于事。关于为什么这在 IE 中不起作用的任何想法?

这会在 Chrome 和 Firefox 中创建这个 html:

<div class="imgframe" style="background:url(images/new.png), url(images/boxart/blah.jpg);"></div>

但在 IE 中显示:

<div class="imgframe"/>
4

1 回答 1

3

那个怎么样?

$(".posternew .imgframe").css("background-image", "url('images/new.png')");

无需解析style属性,只需使用.css().

于 2013-01-06T17:50:19.257 回答