Javascript 在jquery中设置背景图像无效

Javascript 在jquery中设置背景图像无效,javascript,jquery,css,Javascript,Jquery,Css,我使用下面的代码来显示使用jquery加载文档时的图像。 但它没有显示图像。 我的代码是 $(文档).ready(函数(){ $('#cover img').css(“背景图像,”http://webneel.com/wallpaper/sites/default/files/images/04-2013/island-beach-scenery-wallpaper.jpg"); }); 。默认\u封面\u图像{ 位置:相对位置; 宽度:1350px; 高度:320px; 左:0; 排名:0;

我使用下面的代码来显示使用jquery加载文档时的图像。 但它没有显示图像。 我的代码是

$(文档).ready(函数(){
$('#cover img').css(“背景图像,”http://webneel.com/wallpaper/sites/default/files/images/04-2013/island-beach-scenery-wallpaper.jpg");
});
。默认\u封面\u图像{
位置:相对位置;
宽度:1350px;
高度:320px;
左:0;
排名:0;
背景色:#b8dcf4;
}

您忘记添加
url()

语法是:

background-image: url('path');
但你给出了:

background-image: path;
片段

$(文档).ready(函数(){
$('#cover img').css(“url('background-image'),”http://webneel.com/wallpaper/sites/default/files/images/04-2013/island-beach-scenery-wallpaper.jpg')");
});
。默认\u封面\u图像{
位置:相对位置;
宽度:1350px;
高度:320px;
左:0;
排名:0;
背景色:#b8dcf4;
}

您忘记添加
url()

语法是:

background-image: url('path');
但你给出了:

background-image: path;
片段

$(文档).ready(函数(){
$('#cover img').css(“url('background-image'),”http://webneel.com/wallpaper/sites/default/files/images/04-2013/island-beach-scenery-wallpaper.jpg')");
});
。默认\u封面\u图像{
位置:相对位置;
宽度:1350px;
高度:320px;
左:0;
排名:0;
背景色:#b8dcf4;
}
怎么样

$('#cover-img').css("background-image", "url('http://webneel.com/wallpaper/sites/default/files/images/04-2013/island-beach-scenery-wallpaper.jpg')");
怎么样

$('#cover-img').css("background-image", "url('http://webneel.com/wallpaper/sites/default/files/images/04-2013/island-beach-scenery-wallpaper.jpg')");

您可以提供一个带有背景图像的自定义类,稍后在文档加载时,您可以将该类添加到所需的元素

试试这个


您可以提供一个带有背景图像的自定义类,稍后在文档加载时,您可以将该类添加到所需的元素

试试这个