I don't know why does this code not work on chrome and safari, but in mozilla works fine?

$('#id').css('background-image','url(/image.png)');

I also tried this

$('#id').css('background-image','url("/image.png")');
$('#id').css('backgroundImage','url("/image.png")');
$('#id').css('backgroundImage','url(/image.png)');

but still doesn't work.

没有正确的解决方案

其他提示

where do you put the image file (image.png)? If it is in the same directory as in the .html file, you could try this

$('#id').css('background-image','url("image.png")');

$('selector').css('backgroundImage','url(images/myImage.jpg)');
$('selector').css({'background-image':'url(images/myImage.jpg)'});

The latter example allows for multiple rules. Check out the API for more details.

Edit: Make sure your path(s) to your image(s) are correct by inspecting the console. That should tell you if you are getting a 404.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top