码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-01-24 10:57:03      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:his   prototype   key   dir   win   arguments   class   type   elements   

 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         }

 

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

标签:his   prototype   key   dir   win   arguments   class   type   elements   

原文地址:http://www.cnblogs.com/webSong/p/6346551.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!