<!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=!null)
?????????????????????{window.open(url,'_blank','width=400px,height=500px,menubar=no,toolbar=no');
?????????????????}
?????????????????else
?????????????????{alert("再見!");}
?????????else
?????????{alert("再見!");}
????}
????//?新窗口打開時彈出確認框,是否打開
????//?通過輸入對話框,確定打開的網址,默認為?http://www.xianlaiwan.cn/
????//打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
????
????
??</script>?
?</head>?
?<body>?
??<input?type="button"?value="新窗口打開網站"?onclick="openWindow()"?/>?
?</body>
</html>
2018-02-18
使用IDE可以很清楚的看到:第一個問題是中英文符號的問題,在第11行最后那個括號錯誤地變成了中文括號;第二個問題是括號的匹配問題,第一個if執行完true操作后沒有大括號封口導致else無法匹配,報錯。
另外,文件頭設置應將charset改為utf-8,使用gbk會導致瀏覽器打開時出現亂碼。
附上修改后的代碼:
<!DOCTYPE?html> <html> ?<head> ??<title>?new?document?</title>?? ??<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"/>??? ??<script?type="text/javascript">?? ???????function?openWindow() ????????{var?open=confirm("是否打開?"); ????????if(open) ??????????{var?url=prompt("輸入網址","http://www.xianlaiwan.cn/"); ?????????????????if(url?!=?null) ?????????????????????{window.open(url,'_blank','width=400px,height=500px,menubar=no,toolbar=no'); ?????????????????} ?????????????????else ?????????????????{alert("再見!");} ??????????} ?????????else ?????????{alert("再見!");} ????} ????//?新窗口打開時彈出確認框,是否打開 ? ????//?通過輸入對話框,確定打開的網址,默認為?http://www.xianlaiwan.cn/ ? ????//打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。 ????? ????? ??</script>? ?</head>? ?<body>? ??<input?type="button"?value="新窗口打開網站"?onclick="openWindow()"?/>? ?</body> </html>2018-02-09
不知道為啥第一個答案被吃了。。。。。。。。。。。。。。。沒有和?
function?openWindow()????????{對應的花括號,在最后面加一個“}” 就行了
2018-02-09
()?{ ????????open?=?()(open?==?)?{ ????????????url?=?()(url?=?!)?{ ????????????????.(url)}?{ ????????????????()}?}?{ ????????????()}?}