首页 > 其他分享 >jQuery的Command模式插件 command.js

jQuery的Command模式插件 command.js

时间:2023-03-20 20:02:54浏览次数:35  
标签:jQuery function 插件 console log elem js state



基于jQuery的Command模式插件。

该插件将页面元素看成是一个个的对象,通过插件给对象赋予特定的状态,并定义特定的Command。一旦发生关联操作的时候,可以通过通知修改状态或者发布命令的方式进行关联操作。

例如:

$(function(){
$(".a").commands({
states : [{
state : "selected",
paint : function($elem,state){
console.log(state);
},
drop : function($elem,state) {
console.log("drop:" + state);
}
},{
state : "unselected",
paint : function($elem,state){
console.log(state);
},
drop : function($elem,state) {
console.log("drop:" + state);
}
}],
commands : [{
name : "select",
action : function($elem,state){
$elem.state("selected");
}
}]
});

$(".a").state("unselected");
$(".a").command("select");
console.log($(".a").currentState());
});

标签:jQuery,function,插件,console,log,elem,js,state
From: https://blog.51cto.com/u_3871599/6138552

相关文章