JS setTimeout() 传参
来源:互联网 发布:sqlserver union 编辑:程序博客网 时间:2024/06/01 07:26
setTimeout() 使用方式参考w3school。
setTimeout 使用方式: var t = setTimeout("javascript statement", milliseconds);
实例:
setTimeout("hello", 1000); // 每1秒執行一次 hello().
setTimeout("hello()", 1000); // 每1秒執行一次 hello().
setTimeout 带参数:
1.网上有一种字符串拼接的方法: setTimeout("hello(" + value + ")", 1000); 经测试只有传递非字符时有效。
<html> <head> <meta http-equiv="contentType" content="text/html;charset=utf-8"> <script src="http://code.jquery.com/jquery-latest.js"></script> <script>function exec_func(value){alert(value);setTimeout("exec_func(" + value + ")", 3000);//如果参数为字符串的话在第二次执行时字符串为变量,会报未定义的错误。}$(document).ready(function(){exec_func(1);exec_func("hello"); //这句话会报错,错误为 hello未定义。});</script> </head> <body> <div></div></body> </html>
2.修改后的方法(个人推荐):
<html> <head> <meta http-equiv="contentType" content="text/html;charset=utf-8"> <script src="http://code.jquery.com/jquery-latest.js"></script> <script>function exec_func(value){alert(value);setTimeout(function(){exec_func(value)}, 3000);}$(document).ready(function(){exec_func('Hi,Gril');});</script> </head> <body> <div></div></body> </html>
0 0
- JS setTimeout() 传参
- js setTimeout()
- js setTimeout
- js setTimeout
- js计时 setTimeout(转+)
- js setTimeOut 用法
- js中的setTimeout详解
- js setTimeout 参数传递
- js 的settimeout
- 关于js setInterval setTimeout
- js中setTimeout、setInterval
- JS setTimeout小用法
- js setTimeout and setInterval
- js setTimeout 参数传递
- js setTimeout而不是setTimerOut
- js setTimeOut 方法
- js setTimeout 常见问题
- js demo setTimeout
- mapreduce在倒排索引中练习
- 动态规划0—1背包问题
- POJ - 2456 Aggressive cows(二分搜索:最大化最小值)
- scroller view滚动的简单使用方法
- The Last Practice
- JS setTimeout() 传参
- C++ primer第二次阅读学习笔记(第11章:泛型算法)
- viewport meta 标签在手机浏览器上控制布局
- 如何百度蜘蛛喜欢你
- C++与VB异同之面向对象方法比较(一)
- Children’s Queue
- Androidannotations——开源框架简介&简易使用准备
- 贪心算法之哈夫曼编码
- 蟠桃记