这道题目的要求是:
1、点击一个按钮,打开一个确认框,请用户确认是否需要打开网站。如果用户点击确认进入下一步;如果用户点击取消则弹出对话框,对话框显示“下次再见”。
2、用户在上一步点击确认后,弹出一个可输入内容的对话框,对话框默认地址为http://www.baidu.com。如果用户点击确认,则按照一定要求打开一个长度400px,宽度500px,无菜单栏,无工具条的新窗口;如果用户点击取消则弹出对话框,对话框显示“下次再见”。
我的答案是:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
<script type="text/javascript">
function openWindow()
{
var st=confirm("你确定要打开窗口吗?");
if(st==true);
{
var sp=prompt("默认网站是","http://www.baidu.com");
if(sp==null);
{window.open(url,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');}
}
else
{
alert("The end");
}
else
{
alert("The end");
}
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
请问下这个答案哪里有错呢?为什么点击按钮后根本没有执行,求解。
ringa_lee2017-04-10 17:13:31
问题不少。。。
语法错误
{} 嵌套错误
修正后的
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
<script type="text/javascript">
function openWindow()
{
var st = confirm("你确定要打开窗口吗?");
if (st)
{
var sp = prompt("默认网站是","http://www.baidu.com");
if (sp)
{
window.open(sp,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');
}
} else {
alert("The end");
}
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
PHPz2017-04-10 17:13:31
if嵌套错误,修改为:
<script type="text/javascript">
function openWindow(){
var st=confirm("你确定要打开窗口吗?");
if(st==true) {
var sp = prompt("默认网站是", "http://www.baidu.com");
if (sp == null) {
window.open(url, "_blank", 'width=400px,height=500px,menubar=no,toolbar=no');
} else {
alert("The end");
}
}else{
alert("The end");
}
}
</script>
迷茫2017-04-10 17:13:31
我是来凑热闹的……
<script type="text/javascript">
function openWindow() {
var sp
if(confirm('你确定要打开窗口吗?') && (sp = prompt('默认网站是', 'http://www.baidu.com')))
window.open(sp, '_blank', 'width=400px,height=500px,menubar=no,toolbar=no')
else
alert('下次再见')
}
</script>