您的位置:首页 > Web前端 > CSS

模仿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         }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: