任务1、新窗口打开时弹出确认框,是否打开提示: 使用 if 判断确认框是否点击了确定,如点击弹出输入对话框,否则没有任何操作。2、通过输入对话框,确定打开的网址,默认为 http://www.imooc.com/3、打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。<!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 mymessage=confirm("是否打开新网址"); if(mymessage==true){ var a=prompt("确定网址"); if(a=null){ window.open("http//www.imooc.com","_blank","width=400px,height=500px,menubar=no,toolbar=no"); } else{ window.open(a,"_blank","width=400px,height=500px,menubar=no,toolbar=no"); } } else{ alert("你个傻帽!"); } } // 通过输入对话框,确定打开的网址,默认为 http://www.imooc.com/ //打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。 </script> </head> <body> <input type="button" value="新窗口打开网站" onclick="openWindow()" /> </body></html>
1 回答
千秋此意
TA贡献158条经验 获得超188个赞
if (a = null) {
// 你这里把 比较 写成了 赋值, 这里会先给a赋值为null,再执行if语句
// null为false所以走else
// else里 open(a,...),此时a为null,所以打不开
window.open("http//www.imooc.com", "_blank", "width=400px,height=500px,menubar=no,toolbar=no");
} else {
window.open(a, "_blank", "width=400px,height=500px,menubar=no,toolbar=no");
}下面是正确的写法:
<!DOCTYPE html>
<html>
<head>
<title>
new document
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
/**
* 任务
* 提示: 使用 if 判断确认框是否点击了确定,如点击弹出输入对话框,否则没有任何操作。
* 1、新窗口打开时弹出确认框,是否打开
* 2、通过输入对话框,确定打开的网址,默认为 http://www.imooc.com/
* 3、打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。
*/
// 新窗口打开时弹出确认框,是否打开
function openWindow() {
var mymessage = confirm("是否打开新网址");
if (mymessage == true) {
var a = prompt("确定网址", "http://www.imooc.com/");
if (a !== null) {
window.open(a, "_blank", "width=400px,height=500px,menubar=no,toolbar=no");
}
} else {
alert("你个傻帽!");
}
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>添加回答
举报
0/150
提交
取消
