2013-03-09 53 views
1

我想在嵌入式樣式聲明中使用JavaScript變量屏幕作爲樣式backgroundattribute。如何在嵌入式樣式中獲取javascript變量

<div id ="content" style=" position: relative; top: -400px; left: 0px; width: 60px; height: 400px; z-index: 901;background-image: url(' + screen + ') "></div> 
+0

閱讀本 - http://stackoverflow.com/questions/710275/how-to-add-update-an-attribute-to-an-html-元素使用javascript – blackhawk 2013-03-09 19:11:12

回答

1
document.write('<div id ="content" 
    style=" 
    position: relative; 
    top: -400px; 
    left: 0px; 
    width: 60px; 
    height: 400px; 
    z-index: 901; 
    background-image: url(' + screen + ') 
    "> 
</div>') 

document.getElementById('content').style.backgroundImage = screen; 
+0

我想知道如果它可以做我的代碼,但它不能我想。 – wetlip 2013-03-10 00:10:18