如何在内联样式中获取javascript变量

时间:2013-03-09 15:23:37

标签: javascript styles inline

我想在内联样式声明中使用javascript变量屏幕作为样式backgroundattribute。

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

1 个答案:

答案 0 :(得分: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;