求助,我這樣寫為什么不能直接關(guān)閉prompt
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript">??
? ? function openWindow(){
? ? var mymessage=confirm("是否打開新的網(wǎng)站?");
? ? var myinput;
? ? if(mymessage==true)
? ? // 新窗口打開時彈出確認(rèn)框,是否打開
? ? {
? ? ? ? myinput=prompt("請輸入網(wǎng)站:");
? ? ? ? if(myinput!="")
? ? ? ? window.open(myinput,'_blank','width=400,height=500,menubar=no,toolbar=no');
? ? ? ? else if(myinput=="")
? ? ? ? window.open('idcbgp.cn','_blank','width=400,height=500,menubar=no,toolbar=no');
? ? ? ? else myinput.close();
? ? }
? ? else mymessage.close();
? ? }
? ? // 通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ??
? ??
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2019-07-23
所以prompt()運行后,默認(rèn)都是else,?
而每次prompt()窗口結(jié)束前都會去運行這個else中的語句(必定執(zhí)行的語句),所以當(dāng)你在窗口點擊取消按鈕后(窗口結(jié)束后運行alert語句),運行結(jié)果為以上結(jié)果。?
2019-07-28
你的myinput的值,只有兩種可能,一種是空值,一種是非空值。但是你寫了三個分支。。。
2019-07-23
把else myinput.close();改成if window.close();試試