weixin_慕盖茨5207985
2019-02-11 12: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 a=confirm("是否打开?");
if(a==true)
{var b=prompt("确定打开的网址","http://www.imooc.com/");window.open('http://www.imooc.com/','_blank',width=400,height=500)}
else
{document.write("再见");}
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
现在prompt点击取消也会跳出网页,怎么能不跳出网页?
我试了一下,这个可行
<!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 a=confirm("是否打开?");
if(a==true)
{var b=prompt("确定打开的网址","http://www.imooc.com/");if (b!=null){window.open('http://www.imooc.com/','_blank',width=400,height=500);}else{alert("bye");}}
else
{document.write("再见");}
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
但怎么能让仅仅输入该网址时才跳转网页,输入别的都无效呢
JavaScript入门篇
739817 学习 · 9566 问题
相似问题