沒有默認值
<!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("確定要打開嗎?");
??? // 通過輸入對話框,確定打開的網址,默認為 http://www.xianlaiwan.cn/
??????? if(myMessage=="true"){
??????????? var targetWeb=prompt("請輸入要打開的網址", "http://www.xianlaiwan.cn");
??? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
??????????? if(targetWeb!=null)
??????????????? window.open(targetWeb,'_blank','width=400,height=500,menubar=no,toolbar=no');
??????? }
??????? else {
??????????? targetWeb=prompt("重新輸入網址");
??????? }
??? }
??? openWindow();
? </script>
?</head>
?<body>
?? <input type="button" value="新窗口打開網站" onclick="openWindow()" />
?</body>
</html>
2019-01-20
?if(myMessage=="true"){? 這行 true不應該加雙引號
去掉就可以了
還有你的targetWeb是定義在if中的,我想問會不會在else中算作沒有定義
2019-01-20
你的else是對if(targetWeb!=null)的吧? 那個花括號是不是加錯地方了