variable passing inside a function to another function in javascript
setTimeout("refresh()", 2*15000);
This is a code from my JavaScript.
Here setTimeout is a built in function and refresh is a function which I have declared.
I want to pass a variable (cval1) to this refresh function.
I have tried this:
setTimeout("refres开发者_JAVA百科h(cval1)", 2*15000 );
But it's not working.
What is the exact way to do this?
As first parameter of setTimeout pass a function instead of a string, so you have access to all variables in current scope.
setTimeout(function(){refresh(cval1)}, 2*15000);
精彩评论