function openWindow(){
var message=confirm("是否打开窗口?");
if(message){
var url=prompt("确定打开的网址:",“http://www.imooc.com/”);
window.open(url,_blank','width=400,height=500,menubar=no,toolbar=no'); }
} 为啥运行时点击按钮没反应呢?
<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta charset="UTF-8">
<script type="text/javascript">
function openWindow(){
var message=confirm("是否打开窗口?");
if(message){
var url=prompt("确定打开的网址:",'http://www.imooc.com/');
if(url != null){
window.open('url,_blank','width=400,height=500,menubar=no,toolbar=no');
}
}
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>上述代码可以正确运行,你错误的地方:1,prompt里面的网址引号是中文输入法下的,应该成英文,2,window.open后面少写一个引号3,prompt后面应该加一个判断,当prompt值不为空时再调用window.open方法打开网址
<!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 message=confirm("是否打开窗口?");
if(message){
var url=prompt("确定打开的网址:",“http://www.imooc.com/”);
window.open(url,_blank','width=400,height=500,menubar=no,toolbar=no'); }
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>补充一下,就是这个