command.jsjQuery的Command模式插件
基于jQuery的Command模式插件。
該插件將頁面元素看成是一個個的對象,通過插件給對象賦予特定的狀態(tài),并定義特定的Command。一旦發(fā)生關(guān)聯(lián)操作的時候,可以通過通知修改狀態(tài)或者發(fā)布命令的方式進行關(guān)聯(lián)操作。
例如:
$(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());
});評論
圖片
表情
