不知道為什么不行,求解答
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript">??
? ??
? ? // 新窗口打開時彈出確認框,是否打開
? ?
? ? // 通過輸入對話框,確定打開的網(wǎng)址,默認為 http://idcbgp.cn/
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ? ?
? ? ?function openWindow()
? ? {? ?
? ? ? ? var mymessage = confirm('是否打開');
? ? ? ? if (mymessage == true)
? ? ? ? {
? ? ? ? ? ? var new =? prompt("are you sure you want to open it?")
? ? ? ? ? ? if (new == 'sure')
? ? ? ? ? ? {
? ? ? ? ? ? window.open('http://idcbgp.cn/','_blank','width=400, height=500, menubar=no,toolbar=no');
? ? ? ? ? ? }
? ? ? ? }
? ? ? ??
? ? }
? ??
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2019-07-03
?prompt的判定問題,取消你的new==null? ?確定你的new!=null
并且認為要求網(wǎng)址可以自己輸入,只是默認http://idcbgp.cn
所以應(yīng)該是
2019-06-28
? function openWindow()
??? {
??? var mymessage=confirm("是否打開新窗口?");
??? if(mymessage==true)
??? {? var mywin=window.open('http://idcbgp.cn','_blank','width=400,heigh=500,menubar=no,toolbar=no')?? }??
??? else
??? {? mywin.close();?? }
? ? ? ??
??? }
題目上說是“使用 if 判斷確認框是否點擊了確定”, 而不是輸入確定,所以不需要用prompt彈出消息對話框(包含一個確定按鈕、取消按鈕與一個文本輸入框),而是直接用confirm彈出對話框(包含一個確定,一個取消按鈕),他倆的區(qū)別就是prompt消息對話框有文本輸入框,而這里不需要輸入,而是直接點擊“確定”。?