confirm的窗口打不開,怎么回事啊?
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/> ??
? <script type="text/javascript"> ?
? ??
? ? // 新窗口打開時彈出確認(rèn)框,是否打開
? ? function openWindow()
? ? {
? ? ? ? var open=confirm("是否打開新窗口?");
? ? ? ? if(open==true)
? ? ? ? {
? ? ? ? ? ? // 通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
? ? ? ? ? ?var new=prompt("輸入要打開的網(wǎng)址","http://idcbgp.cn/");
? ? ? ? ? ? if(new!=null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ? ? ? ? ? ? ? window.open(new,'_blank','width=400px,height=500px,menubar=no,toolbar=no');
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? alter("再見");
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? ?alter("再見");
? ? ? ? }
? ? }
? ??
? </script>?
?</head>?
?<body>?
?<input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2019-08-11
首先var new=prompt("輸入要打開的網(wǎng)址","http://idcbgp.cn/");這一行有問題,變量名不能選擇為關(guān)鍵詞。然后將所有引用的地方的變量名都改為新的變量名
變量名可以任意取名,但要遵循命名規(guī)則:
? ? 1.變量必須使用字母、下劃線(_)或者美元符($)開始。
? ? 2.然后可以使用任意多個英文字母、數(shù)字、下劃線(_)或者美元符($)組成。
? ? 3.不能使用JavaScript關(guān)鍵詞與JavaScript保留字。