function aa() {
            var a = "width:100px;color:red";
            return a;
        
        }
 <div style="javascript:aa()">cccccccccccccccccc</div>
我给这个DIV为什么这样加不了CSS样式。

解决方案 »

  1.   

    你直接写<div style="width:100px;color:red">cccccccccccccccccc </div> 
    不就行了???
      

  2.   


    function aa(obj) {
                obj.style.cssText = "width:100px;color:red";
           
            }
    <div style="javascript:aa(this)">cccccccccccccccccc </div> 
      

  3.   

            function aa() { 
                width:100px;
                color:red;  
            
            } 
    <div class="aa">cccccccccccccccccc </div> 
      这样写不行吗?
      

  4.   


    <body onload="aa()">
     function aa() { 
                var obj = document.getElementById(dd)
                obj.style.cssText  = "width:100px;color:red"; 
                       
            } 
    <div id="dd" >cccccccccccccccccc </div>