LittleSisterComing
2020-01-07 11:23
<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<script type="text/javascript">
var tip = confirm("在?打开网页?");
if (tip == true) {
var address = prompt("Please input web address", "http://www.imooc.com/");
function openWindow() {
window.open('address', '_blank', 'width=400px', 'height=500px');
}
}
else { }
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
好像逻辑就错了吧,函数openWindow()
应该把'var tip = confirm("在?打开网页?");'包住吧;另外,"http://www.imooc.com/"里的“:”为中文状态下的,改为英文状态下的:
<!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 tip = confirm("在?打开网页?");
if (tip == true) {
var address = prompt("Please input web address", "http://www.imooc.com/");
//function openWindow() {
window.open('address', '_blank', 'width=400px', 'height=500px');
// }
}
else { }
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
最后打开网址前应在加个判断,否则点取消也会打开个空网址
JavaScript入门篇
739818 学习 · 9566 问题
相似问题