var v6 = "/images/2009/11/21/0000/200911211511140037.png";

var turl = "." + v6 ;
   
    var disply = document.getElementById("displayimg");
    alert(disply.currentStyle.backgroundImage);
    var url = "url( " + turl + " )";
    alert(url);
    disply.currentStyle.backgroundImage = url  ;
    alert(disply.currentStyle.backgroundImage);
这样的代码 会有错
disply.currentStyle.backgroundImage = url  ;

解决方案 »

  1.   

    disply.currentStyle.backgroundImage = url  ; 
    改为
    disply.currentStyle.backgroundImage.src = url  ; 试试看?
      

  2.   

    disply.style.backgroundImage = url;
      

  3.   

    我的需求 是我修改style, 然后 让所有使用这个style 的div 都修改的
      

  4.   


    <html>
    <head>
     <title>Untitled</title>
     <style type="text/css">
        .div {
            background:url(http://avatar.profile.csdn.net/F/4/D/2_im2web.jpg) no-repeat;
            width:300px;
            height:200px;
        }
    </style>    
    </head>
    <body>
    <div id="div1" class="div">
    </div>
    <div class="div">
    </div>
    <input type="button" value="修改背景" id="btnModify"/>
    </body>
    <script type="text/javascript">
    var g=function(id) {return document.getElementById(id)};var Style={
        ss:document.styleSheets[0],
        insertRule: function(selector,styles) {
            var n=(this.ss.cssRules?this.ss.cssRules:this.ss.rules).length;
            if (this.ss.insertRule)   // Try the W3C API first
                this.ss.insertRule(selector + "{" + styles + "}", n);
            else if (this.ss.addRule) // Otherwise use the IE API
                this.ss.addRule(selector, styles, n);
        }
    };
    g("btnModify").onclick=function() {
        var img="http://avatar.profile.csdn.net/6/D/1/2_sohighthesky.jpg";
        Style.insertRule(".div","background-image:url("+img+")");
    }
    </script>
    </html>
      

  5.   

    你的代码只是改变了某个obj对象的背景图片,不如给需要改变背景的对象加个标识,当需要改变的时候,循环这些对象动态改变