2014-12-27 144 views
0

我想设置一个div的图像。此代码不起作用:解析设置图像javascript

var myUrl=profilePhotoFile.url() 
    var div=document.getElementById("vignette") 
    console.log(div) 
    div.style.content="url(profilePhotoFile.url()) no-repeat"; 

profilePhotoFile.url()返回一个字符串,顺便

回答

0

你可能意味着

div.style.content="url("+profilePhotoFile.url()+") no-repeat"; 

不过,我不认为不重复是用于内容,通常它是用于背景图像

1

我想你正在尝试将图像设置为背景。

如果是

//var myUrl=profilePhotoFile.url() 
//setting temp image URL 
var myUrl = "https://www.google.co.in/images/srpr/logo11w.png"; 
var div = document.getElementById("vignette"); 
div.style.backgroundImage="url("+myUrl+")"; 
div.style.backgroundRepeat="repeat-y"; 

的jsfiddle网址:http://jsfiddle.net/naveenkumarpg/o0c6LLo0/1/

如果哟要设置在侧的小插曲容器图像

//var myUrl=profilePhotoFile.url() 
//setting temp image URL 
var myUrl = "https://www.google.co.in/images/srpr/logo11w.png"; 
var div = document.getElementById("vignette"); 
div.innerHTML="<img src="+myUrl+">"; 

的jsfiddle:http://jsfiddle.net/naveenkumarpg/o0c6LLo0/2/