setTimeout方法里面的方法如果有參數(shù)怎么辦
<!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是傳進來的參數(shù),但是要怎么改才能讓它顯示傳進來的message呢
2018-10-10
第 9 行,
發(fā)現(xiàn),setTimeout 里 alert 那的單引號去掉就可以執(zhí)行了,但不清楚為什么不是 5s 后彈出提示框。
2018-09-30
定時器的方法里面不要亂傳東西...謝謝