幻夏泡影
2015-10-05 18:05
<!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 str=confirm("是否打开?");
// 新窗口打开时弹出确认框,是否打开
if(str==ture)
{var str1=prompt("请输入网址:","http://www.imooc.com/");
}
// 通过输入对话框,确定打开的网址,默认为 http://www.imooc.com/
if(str1!=null)
{
window.open("http://www.imooc.com/","_blank","width=40px,height=500px,menubar=no,tollbar=no");
}
else
{alert("打开失败");}
else
{ alert("打开失败");}
}
//打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。
</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 str=confirm("是否打开?");
// 新窗口打开时弹出确认框,是否打开
if(str==true){
var str1=prompt("请输入网址:","http://www.imooc.com/");
}
// 通过输入对话框,确定打开的网址,默认为 http://www.imooc.com/
if(str1 !=null){
window.open("http://www.imooc.com/","_blank","width=40px,height=500px,menubar=no,tollbar=no");
} else {
alert("打开失败");
}
}
//打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>两个地方错误,第一是str==true而不是str==ture,这可以简写的。因为这是判断布尔值所以可以直接用if(str),第二个地方
else {
alert("打开失败");
}这个多写了一个,if可以当独出现。但是else必须和if成对出现。
<!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 s=confirm("是否打开新窗口?");
var s2;
if(s==true){
//alert(s);
s2=prompt("请输入网址:","http://www.imooc.com/")
//alert(s2);
if(s2!=null){
window.open('http://www.imooc.com','_blank','width=400,height=500,menubar=yes,toolbar=yes');
}else{
alert('仍需努力!');
}
}
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>大概修改了下,除了此处
if(str==ture)
{var str1=prompt("请输入网址:","http://www.imooc.com/");
}
str1被定义成为了一个局部变量,还有就是(str==ture)此处应该是true,最后呢连续俩个else是几个意思?
JavaScript入门篇
741811 学习 · 9869 问题
相似问题