為什么把延時(shí)程序加進(jìn)去后, 不能正常關(guān)閉打開的窗口
我的想法是, 打開窗口后,5S就自動(dòng)關(guān)閉,這樣可以看清楚效果,?
?<script type="text/javascript">
? ? ?var mywin=window.open("http://idcbgp.cn");
? ? ?setTimeout("mywin.close()",5000);
? </script>
</head>
<body>
</body>
寫成上面這樣, 可以正常顯示,但是加了button和函數(shù)調(diào)用以后, 就失效了, 想破腦袋也不知道原因在哪里
?<script type="text/javascript">
? function tim()
? {
? ? ?var mywin=window.open("http://idcbgp.cn");
? ? ?setTimeout("mywin.close()",5000);
}
? </script>
</head>
<body>
<input type="button" id="count" onClick="tim()" value="打開新網(wǎng)頁"/>
</body>
2016-09-23
我用的是sublime text3和chrome調(diào)試,還有setTimeout方法建議你去w3c再看看
http://www.w3school.com.cn/jsref/met_win_settimeout.asp
2016-09-21
我試了一下你的代碼,是沒問題的,這是照你的代碼打好的,你試試
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="UTF-8">
? ? <title>Document</title>
? ? ?<script type="text/javascript">
? ? ? ? function tim(){
? ?var mywin=window.open("http://idcbgp.cn");
? ? setTimeout("mywin.close()",5000);
? ? ? ? ? ? }
? </script>
</head>
<body>
<input type="button" id="count" onClick="tim()" value="打開新網(wǎng)頁"/>
</body>
</html>
2016-09-21
好像不可以