我在jQuery-wrapper中有一个函数changeGraph(),我需要从外面以某种方式调用它。我需要从基于jQuery的图库Flot中访问函数setData。
来源看起来像这样:
function changeGraph(){
// I need to access $.plot.setData somehow
};
var d2 = [[0, 0], [20, 300000]];
$(function () {
$.plot($("#placeholder"),
[{color: "#000000", data: d2}],
{
series: {
lines: { show: true, fill:true, fillColor: {colors: [ "#d1ddea","#8e959d"]}},
points: { show: false }
}
}
);
});
我该如何做到这一点?
答案 0 :(得分:8)
var changeGraph;
$(function () {
changeGraph = function () {
// Need to access $.plot($("#placeholder") here
};
});
changeGraph(); // call this when document is ready at least
答案 1 :(得分:2)
您应该将函数移出回调函数。
答案 2 :(得分:2)
function changeGraph() {
// ...
}
$(function() {
changeGraph();
});