a746785570
2015-03-02 15:03
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>close()</title>
<script type="text/javascript">
function a()
{
var b=confirm("你确定打开慕课吗?")
if(b==true)
{window.open('http://www.imooc.com','_blank','width=300,height=200,menubar=no,toolbar=no,')}
else if(c!=null)
var c=prompt("请输入你喜欢的网址:");
{window.open(c,'_blank','width=300,height=200,menubar=no,toolbar=no,')}
else
{alert("真的没有喜欢的网址吗?")}
}
</script>
</head>
<body>
<input type=submit onClick="a()" value="点我点我">
</body>
</html>
分享下我的看法吧:
你没有理解题意,confirm只是询问用户是否接受弹出消息窗口,也就是prompt窗口
顺着你的思路的话,你的else if语句判断条件出错了,应该是else if(b != null)
而且你的else if后面要紧跟花括号啊,你的花括号掉到下一行了,那么就只执行了var c=prompt("请输入你喜欢的网址:");语句
你在这里强行用else if真是没必要,因为confirm返回值只有true和false,你已经判断过为true的情况了,直接else就可以了
if(b == true) {
window.open('http://www.imooc.com','_blank','width=300,height=200,menubar=no,toolbar=no,')
}
else {
var c = prompt("请输入你喜欢的网址:","http://www.imooc.com");
if(c != null) {
window.open(c,'_blank','width=300,height=200,menubar=no,toolbar=no,')
}
else {
alert("真的没有喜欢的网址吗?");
}
}5. 代码缩进格式可以规范点哦
function openWindow() {
var answer = confirm("是否弹出对话框?");
if(answer == true) {
// 设置默认网址为百度
var website = prompt("请输入你想打开的网站:","http://www.baidu.com");
if(website != null) {
window.open(website,"_blank","width=400,height=500,menubar=no,toolbar=no");
}
else {
// 如果用户点取消,将触发该提示
alert("好吧,什么都没有发生过··");
}
}
}我是这么写的,互相学习
else if 后面怎么这样写
JavaScript入门篇
741596 学习 · 9869 问题
相似问题