JavaScript 操作 Css
當(dāng)前位置:點(diǎn)晴教程→知識管理交流
→『 技術(shù)文檔交流 』
/*****************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){ //去掉-并轉(zhuǎn)換-后的字符為大寫 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對象,批量設(shè)置 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" }); }; 該文章在 2010/8/13 19:11:15 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |