turboburst
2018-09-30 08:53
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>setTimeout</title>
<script type="text/javascript">
var delayTime;
function showAlertAfter(waitingTime, message){
delayTime = window.setTimeout('alert(message)', waitingTime);
}
</script>
</head>
<body>
<input type="button" value="clickme" onclick="showAlertAfter(5000,'Hello world')"/>
</body>
</html>上面的代码,运行会没有反应,因为window.setTimeout('alert(message)', waitingTime);这一行不行,因为message是传进来的参数,但是要怎么改才能让它显示传进来的message呢
第 9 行,
delayTime = window.setTimeout('alert(message)', waitingTime);发现,setTimeout 里 alert 那的单引号去掉就可以执行了,但不清楚为什么不是 5s 后弹出提示框。
定时器的方法里面不要乱传东西...谢谢
JavaScript进阶篇
469065 学习 · 22582 问题
相似问题