<!doctype html> <html> <head> <meta charset="utf-8"/> <title>電燈開關案例</title> <script> /** 練習:點擊按鈕,開燈或關燈 */ var flag = false;//false表示默認狀態為關燈 function changeImg(){ console.log("this is show work good!"); showInfo=window.open("3.html",'','width=200,height=100'); } function closeit() { setTimeout("showInfo.close()", 2000) //毫秒 } </script> </head> <body> <input type="button" value="開/關燈" onclick="changeImg()" /> <br/><br/> <body onload="closeit()"> </body> </html>