<!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 open=confirm("是否打开"); if(open==true) { var ope=prompt("shuru","http://www.imooc.com/");} if(ope!=null){ window.open("ope",'width=400','height=500''_blank','menubar=no','toolbar=no')}; else{ window.open(' ope','width=400','height=500''_blank','menubar=no','toolbar=no')}; else { alert("bye");} } </script> </head> <body> <input type="button" value="新窗口打开网站" onclick="openWindow()" /> </body> </html>
花括号嵌套错乱了。
window.open("ope",'width=400','height=500''_blank','menubar=no','toolbar=no')};
这里变量ope是不需要加引号的。后面的参数直接用一对单引号就可以了。
修改后的代码你看看
<!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 open=confirm("是否打开"); if(open==true){ var ope=prompt("shuru","http://www.imooc.com/"); if(ope!=null){ window.open(ope,'width=400,height=500,_blank,menubar=no,toolbar=no'); }else{ window.open(ope,'width=400,height=500,_blank,menubar=no,toolbar=no'); } }else{ alert("bye"); } } </script> </head> <body> <input type="button" value="新窗口打开网站" onclick="openWindow()" /> </body> </html>