Flot:如何添加“mousedown”事件给情节持有者?
我想在 JQuery/Flot 代码中向绘图持有者添加 "mousedown"
事件,我尝试了两种方法,但都不起作用,我感谢任何人给我任何提示!
1)
placeholder.bind("mousedown",function(e){
alert("1");
})
2)
function onMouseDown(e) {
alert("1");
}
plot.hooks.bindEvents.push(function (plot, eventHolder) {
eventHolder.mousedown(onMouseDown);
});
I want to add "mousedown"
event to the plot holder in JQuery/Flot code, i tried two ways, but neither works, i appreciate anybody give me any hints!
1)
placeholder.bind("mousedown",function(e){
alert("1");
})
2)
function onMouseDown(e) {
alert("1");
}
plot.hooks.bindEvents.push(function (plot, eventHolder) {
eventHolder.mousedown(onMouseDown);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Simon,
如果它们是在 DOM 之后动态添加的元素,请尝试 live。如果在运行时添加它们,则正常绑定不起作用。
http://api.jquery.com/live/
Simon ,
If they are dynamically added elements after the DOM , try live . Normal bind doesn't work if they are added at run time.
http://api.jquery.com/live/
我猜您错误地调用了
$.plot
返回的内容。它不会返回一个 jQuery 对象,而是返回一个Plot
对象。因此,最有可能的是,如果您的 HTML 有类似这样的内容:
您想要执行如下绑定:
I would guess that you've mistaken what the call to
$.plot
returns. It doesn't give you back a jQuery object, it gives you back aPlot
object.So most likely, if you have something like this as your HTML:
You want to do a bind like this:
在flot中,您可以使用钩子来绑定事件。有一个名为bindEvents 的钩子,您可以使用它来绑定任何事件。
示例:
文档对此有很详细的说明
https://github.com/flot/flot/blob/master/API。 MD
In flot , You can bind events using hooks . There is a hook called bindEvents which you can use to bind any event.
example:
The Documentation is in good detail about this
https://github.com/flot/flot/blob/master/API.md