我已经使用可视化函数创建了一个动态条形图,并且形象化.css 图形的值是通过 HTML 表给出的,现在我想在该图形上执行一个事件。
user1791122
问问题
106 次
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 回答