简体   繁体   English

在SetInterval函数外部更新变量值

[英]Update Variable Value Outside SetInterval Function

function circleStat(elem1, pvalue, ccolor) {
    var cx = document.getElementById(elem1);
    var percentage = 0;
    var dataval = pvalue;
}

Hi, 你好

I am using this above mentioned code in one of my javascript projects. 我在我的一个JavaScript项目中使用了上述代码。 I would like to increase the value of percentage from 0 to datavalue (which is equal to pvalue parameter in the above mentioned function). 我想将百分比的值从0增加到datavalue(等于上述函数中的pvalue参数)。

And from that I would like the increasing value of percentage to be updated constantly. 从那以后,我希望不断增加百分比的价值。 So, I can use it in another variable of this same function. 因此,我可以在同一功能的另一个变量中使用它。 So, how to get the updated value of percentage from setInterval? 那么,如何从setInterval获取百分比的更新值?

I know callback functions, but don't know how to use it on this one. 我知道回调函数,但不知道如何在此函数上使用它。 Please help... Thanks in advance... 请帮助...预先感谢...

You could make percentage and the other visible to circleStat() and then, 您可以使circleStat()看到一个百分比,另一个可见,然后,

function circleStat() {
    updatePercentage(); // update percentage value
    // do what you need with percentage and the other
}

Now call setInterval( circleStat, someTimeInMs ) . 现在调用setInterval( circleStat, someTimeInMs )

With this you will have the updated value of percentage each time you perform what it is to be performed. 这样,每次执行要执行的操作时,您将获得百分比的更新值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM