/*****************javascript操作css****************
writer:tantaiyizu
date:2008-5-6
msn:danxinju#hotmail.com
********************************************/var css = {
CName: function(name){
var _name = name.replace(/-[A-Za-z]/ ,function(rc){ //去掉-并转换-后的字符为大写
return rc.toUpperCase().replace("-" ,"");
});
return _name;
},
get: function(elem ,name){ var _name = this.CName(name); //_name为IE下属性的名字 if(elem.currentStyle){ //IE方式获取
return elem.currentStyle[_name];
}
else if(document.defaultView && document.defaultView.getComputedStyle){ //w3c方式获取
var s = document.defaultView.getComputedStyle(elem, "");
return s?s.getPropertyValue(name) : "";
} return "";
},
set: function(elem ,arg ,value){ if(typeof arg == "string" && typeof value == "string"){ //传入属性,属性值
arg = this.CName(arg);
elem.style[arg] = value;
}
else if(typeof arg == "object"){ //传入json对象,批量设置
for(var ii in arg){
var _ii = this.CName(ii);
elem.style[_ii] = arg[ii];
}
}
}
};window.onload = function(){
var d = document.getElementById("kp");
var x = css.get(d ,"background-color");
//alert(x)
//css.set(d ,"background-color" ,"#BFD9FF");
css.set(d ,{
"background-color":"#BFD9FF" ,
"height":"300px"
});
};