admin管理员组文章数量:1323510
I've got a function changeGraph() inside the jQuery-wrapper which I need to call somehow from outside it. I need to access the function setData from the jQuery based graph-library Flot.
The source is looking like this:
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 }
}
}
);
});
How can I acplish this?
I've got a function changeGraph() inside the jQuery-wrapper which I need to call somehow from outside it. I need to access the function setData from the jQuery based graph-library Flot.
The source is looking like this:
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 }
}
}
);
});
How can I acplish this?
Share edited Jun 26, 2011 at 20:37 Hedge asked Jun 26, 2011 at 20:25 HedgeHedge 16.8k45 gold badges154 silver badges260 bronze badges 6- Can you move the function outside of the function scope? – Jared Farrish Commented Jun 26, 2011 at 20:27
- I need to access this variable inside the scope $.plot($("#placeholder") , I don't know to do this outside the scope – Hedge Commented Jun 26, 2011 at 20:29
-
@Hedge - Can you post more of your code? I don't know why you couldn't have the
changeGraph()
in the global scope. You might consider, if you need to, using jQuery's$.data()
to pass data into your function. – Jared Farrish Commented Jun 26, 2011 at 20:31 -
You can still use
$
if you move your function outside, like I showed in my answer. – jtbandes Commented Jun 26, 2011 at 20:31 - @jtbandes - I suspect he's got other functions in that scope. The OP needs to provide more context for his problem by posting more code, I think. – Jared Farrish Commented Jun 26, 2011 at 20:34
3 Answers
Reset to default 8var changeGraph;
$(function () {
changeGraph = function () {
// Need to access $.plot($("#placeholder") here
};
});
changeGraph(); // call this when document is ready at least
You should move your function outside of the callback function.
function changeGraph() {
// ...
}
$(function() {
changeGraph();
});
本文标签: javascriptHow to call inner function of jQuerywrapper (function()Stack Overflow
版权声明:本文标题:javascript - How to call inner function of jQuery-wrapper $(function() { }? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742138656a2422484.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论