模仿jq里的选择器和color样式
2017-01-24 10:20
337 查看
1 (function(){ 2 HTMLElement.prototype.css = function () { 3 var option; 4 if (arguments.length > 0) { 5 option = arguments[0]; 6 if (2 === arguments.length) { 7 option = {}, option[arguments[0]] = arguments[1]; 8 } 9 10 if ('object' === typeof option) { 11 for (var key in option) { 12 if (option.hasOwnProperty(key)) { 13 this.style[key] = option[key]; 14 } 15 } 16 } 17 18 } 19 console.dir(this) 20 return this; 21 }; 22 23 function $id(id){ 24 return document.getElementById(id); 25 } 26 function $clas(cla){ 27 return document.getElementsByClassName(cla)[0]; 28 } 29 30 window["$id"]=$id; 31 window["$clas"]=$clas; 32 33 })() 34 35 $id('get').onclick=function function_name () { 37 if (true) { 38 $clas('dom').css('background','red'); 39 }; 40 41 }
相关文章推荐
- 使用css中的flex布局弹性手风琴效果
- CSS:margin重叠-父子关系
- 使用css让文字两端对齐
- 修正Sublime Text 3的csslint插件
- CSS之如何绘制任意角度的扇形
- 4000 css 如何实现导航border-bottom 有阴影的感觉
- POI HSSFCellStyle 设置 Excel 单元格样式
- CSS_选择器
- Automating CSS Regression Testing
- 图片居中法之一
- CSS选择器
- web结构样式分离与代码简洁化
- CSS引入样式
- CSS | steps 的内心探索之路
- CSS | 渐变的妙不可言 linear & radial
- css入门教程(一)
- 子元素在父元素里水平居中
- 子元素(div)在父元素(div)里水平且垂直居中
- css框架命名规范
- css元素垂直居中