私は視覚化関数とvisualize.cssを使用して動的な棒グラフを作成しました。グラフの値はHTMLテーブルを介して与えられ、そのグラフでイベントを実行したいと考えています。
1 に答える
0
カスタムイベントを作成します。
(function() {
/**
* Small event class, can be instanciated as an object or using .call used to decorate other
* Objects with events funcitonality.
*/
MyEvent.Event = function() {
this.events = {};
this.bind = function(eventName, func) {
if (!this.events[eventName]) {
this.events[eventName] = [];
}
this.events[eventName].push(func);
};
this.trigger = function(eventName, args, scope) {
if (this.events[eventName]) {
var len = this.events[eventName].length,
funcArgs = (jQuery.isArray(args)) ? args : [args];
// This will go from back to front through the array not sure if this really matters?
while (len--) {
this.events[eventName][len].apply(scope || window, funcArgs);
}
}
}
this.removeAllEvents = function() {
this.events = {};
}
};
// Page level events class
MyEvent.pageEvents = new MyEvent.Event();
})();
それをトリガーします:
MyEvent.pageEvents.trigger("Method-name", "data"));
そして最後にそれを聞いてください:
MyEvent.pageEvents.bind("Method-name", function(Data) {
//Code goes here
});
JQUERYを使用していますか?
トリガーとバインドを見てください。
于 2013-01-10T12:54:16.763 に答える