<!DOCTYPE html> <html> <head> <title>编程练习</title> <meta http-equiv='Content-Type' content='text/html;charset=gbk'/> <script type='text/javascript'> function openWindow() {var open=confirm('确定要打开一个外部网站么?'); if (open==true) {var second=prompt('请确认网址是否正确:','http://cn.bing.com'); if (second!=null) {window.open(open,'_blank','width=500px,height=300px'); else {alert('I still like you!');}} else {alert('I do not hate you!');}} } openWindow() </script> </head> <body> <input type='button' value='点我点我点我' onclick='openWindow()' /> </body> </html>
18行的openWindow调用要去掉的,这个应该是在按钮被点击后触发的。其他的问题也好多,比如中间应该用的是英文的逗号,你用的是中文的逗号,程序肯定编译不过。。。
修正后如下
<!DOCTYPE html>
<html>
<head>
<title>编程练习</title>
<meta http-equiv='Content-Type' content='text/html;charset=gbk'/>
</head>
<body>
<script type='text/javascript'>
function openWindow()
{
var open=confirm('确定要打开一个外部网站么?');
if (open==true)
{
var second=prompt('请确认网址是否正确:','http://cn.bing.com');
if (second!=null)
window.open(second,'_blank','width=500px,height=300px');
else
{alert('I still like you!');}}
}
</script>
<input type='button' value='点我点我点我' onclick='openWindow()' />
</body>
</html>
('second','_blank','width=500px,height=300px');
<!DOCTYPE html>
<html>
<head>
<title>编程练习</title>
<meta http-equiv='Content-Type' content='text/html;charset=gbk'/>
<script type='text/javascript'>
function openWindow()
{var open=confirm('确定要打开一个外部网站么?');
if (open==true)
{var second=prompt('请确认网址是否正确:','http://cn.bing.com');
if (second!=null)
{window.open(open,'_blank','width=500px,height=300px');
else
{alert('I still like you!');}}
else
{alert('I do not hate you!');}}
}
openWindow()
</script>
</head>
<body>
<input type='button' value='点我点我点我' onclick='openWindow()' />
</body>
</html>