function  css(name,value){
var
convertName = pctco.convertHumps('-',name);   //  这里自动会把background-color转义成backgroundColor
this.elements.style.convertName = value;  // 问题出现在这里typeof convertName是字符串 怎么让他变成属性
}css('background-color','red');
主要问题就是出在convertName

解决方案 »

  1.   

    this.elements[0].style[convertName] = value
      

  2.   

    $(elements).css(name,value);
      

  3.   


    <style type="text/css">
    #a {
    width: 200px;
    height: 200px;
    background-color: blue;
    }
    </style>
    <div id="a"></div>
    <script type="text/javascript">
    function  css(name,value,id){     // var
        // convertName = pctco.convertHumps('-',name);   //  这里自动会把background-color转义成backgroundColor
       // document.getElementById(id).style.backgroundColor = value;  // 问题出现在这里typeof convertName是字符串 怎么让他变成属性
       document.getElementById(id).style.cssText = name + ':' + value+';';
    }
    css('background-color','red','a');
    </script>