<!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.imooc.com/");
if(url=!null){
window.open(url,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');
}
}
else
{alert("结束");}
}
//打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。
else
{alert("结束");}
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
function openWindow() { var open = confirm("是否打开新窗口?"); //你这里的 ( 是中文的 if (open == true) { //这里url是true 或 false 不是你输入的地址 var url = prompt("打开新窗口", "http://www.imooc.com/"); if (url) { window.open("http://www.imooc.com/", "_blank", 'width=400px,height=500px,menubar=no,toolbar=no'); //} 这里多了一个 } } else { alert("结束"); } } //打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。 else { alert("结束"); } }
对着注释看
if(url=!null){
这里应该是!=,而不是=!。
!=是不等于,=!是取反后赋值。
if(open==true){
这里的(敲成中文的,改成英文的。
花括号嵌套错乱。括号是成对出现的,删去第一个else前的一个}即可。
修改后的全代码
<!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.imooc.com/"); if(url=!null){ window.open(url,"_blank",'width=400px,height=500px,menubar=no,toolbar=no'); }else{ alert("结束"); } }else{ alert("结束");} } </script> </head> <body> <input type="button" value="新窗口打开网站" onclick="openWindow()" /> </body> </html>