首页 新闻 赞助 找找看

请帮忙修正插件函数错误之处,非常感谢!

0
悬赏园豆:10 [待解决问题]

;(function() {
 "user strict";
 //默认参数
 var size = {
  var options = {
   color: 'red'
  };
 }
 
 //插件函数color
 var color = {
  
  //更新配置参数
  var config: function(opts) {
   if(!opts) return options;
   for (var k in opts) {
    options[k] = opts[k];
   }
   return this;
  },
  
  //监听事件
  var listen: function(elem) {
   var elems = document.getElementById('elem');
        elems.addEventListener('click',function() {
        this.style.color = options.color;
   })  
  }
  return this;
 }
 window.Color = color;
})()

 

//对象链式调用:

//Color.config({color: 'red'}).listen('#sz');

优昙陀罗的主页 优昙陀罗 | 初学一级 | 园豆:188
提问于:2018-07-14 15:29
< >
分享
所有回答(2)
0

这写的是啥?真的乱。没错了,你看看

;(function() {
"user strict";
//默认参数
var options = {
color: 'red'
}


//插件函数color
var color = {

//更新配置参数
config: function(opts) {
if(!opts) return options;
for (var k in opts) {
options[k] = opts[k];
}
return this;
},

//监听事件
listen: function(elem) {
var elems = document.getElementById('elem');
if(elems){
elems.addEventListener('click',function() {
this.style.color = options.color;
})
}
return this;
}
}
window.Color = color;
})()

 

//对象链式调用:

Color.config({color: 'red'}).listen('#sz');

铁柱成针 | 园豆:614 (小虾三级) | 2018-07-15 09:37

z正确答案

 

支持(0) 反对(0) blurs | 园豆:660 (小虾三级) | 2018-07-16 10:37
0

size 本身就是对象了, 里面为什么还要用var声明option

一叶兰舟飘 | 园豆:351 (菜鸟二级) | 2018-07-16 10:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册