慕粉3686312
2016-07-27 19:10
<!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("是否新建网页?");
{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>
<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk2312"/>
<script type="text/javascript">
function openWindow()
{
var opena=confirm("是否新建网页?");
if(opena==true)
{
var url=prompt("通过输入对话框,确定打开的网址","");
if(url!=null&&name!="")
{
window.open(url,"target= _blank","width=400px,height=500px,menubar=no,toolbar=no");
}
else
{
alert("再见");
}
}
else
{alert("再见");
}
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
少了加粗部分是上的一个}
<!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判断语句
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>
去掉多余的大括号,和最后多余的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("是否新建网页?");
var url=prompt("通过输入对话框,确定打开的网址"," http://www.imooc.com");
if(url!=null)
{window.open(url,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');}
else
{alert("再见!");}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
JavaScript入门篇
739818 学习 · 9566 问题
相似问题