模仿jq里的选择器和color样式

 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         }
原文地址:https://www.cnblogs.com/webSong/p/6346551.html