代碼寫成這樣,為什么運行結果不對
<!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 open = confirm("確認是否打開新窗口");
? ? if(open==true)
? ? {
? ? ? ? var url = prompt("請輸入新網址",'http://www.xianlaiwan.cn');
? ? ? ? if(url!="")
? ? ? ? {var openURL=window.open(url,'_blank','wideth=400,height=500,menubar=no,toolbar=no');}
? ? else
? ? {
? ? ? ? alert("bye");
? ? }
? ? }
? ? // 新窗口打開時彈出確認框,是否打開
? ? // 通過輸入對話框,確定打開的網址,默認為 http://www.xianlaiwan.cn/
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ??
? ??
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>
2019-04-25
少了}
2019-04-12
除了樓上提出的拼寫錯誤外(其實不影響整體流程),核心問題是function openWindow()沒有結尾的“}”,所以報錯了。</script> 前面一行加上結尾的“}”就OK了。
2019-04-03
width錯了,不是wideth
2019-04-02
你的寬,高,工具,那些沒有單獨的引號,不知道是不是這個原因,你試試
2019-04-02
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript">??
? ? {document.write();}
? ? function openWindow(){
? ? ? ? var open=confirm("是否打開?");
? ? if(open==true)
? ? window.open('http://www.xianlaiwan.cn/','width=400','height=500','menubar=no','toolbar=no')}
? ? // 新窗口打開時彈出確認框,是否打開
? ? // 通過輸入對話框,確定打開的網址,默認為 http://www.xianlaiwan.cn/
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ??
? ??
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>