為什么我的代碼在打開這個網(wǎng)頁之后,只要點擊關(guān)閉窗口,會無限的再打開新的網(wǎng)頁
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>window對象</title>
<script type="text/javascript">
var string = confirm("歡迎來到慕課網(wǎng)");
function new_page(){
??? if(string==true)
??? {
??????? window.open("http://www.hao123.com","_blank","height=400px,width:600px");
??? }
}
</script>
</head>
<body>
<form>
<input type="button" value="點擊我,打開新窗口" onfocus="new_page()" />
</form>
</body>
</html>
2016-11-04
因為你這里用了onfocus,意思是只要焦點在這個button上;當(dāng)你click后,焦點就會一直 在button上,除非你在文檔空白處隨便點一下,取消焦點,它才不會一直打開窗口