开发者

variable passing inside a function to another function in javascript

开发者 https://www.devze.com 2022-12-14 00:54 出处:网络
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.
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);
0

精彩评论

暂无评论...
验证码 换一张
取 消