Yo11
2018-08-04 15:20
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>close()</title> <script type="text/javascript"> var mywin=window.open("http://www.imooc.com"); var pages=confirm("choose to close the window"); if(pages == 1){ mywin.close(); alert("window has been closed"); } else{ alert("window has NOT been closed!"); } </script> </head> <body> </body> </html>
你也可以这样
var mywin=window.open("http://www.imooc.com");
var pages=confirm("choose to close the window");
if(pages==true){
mywin.close();
alert("window has been closed");
}
else{
alert("window has NOT been closed!");
}
var
pages=confirm(
"choose to close the window"
);
这里的pages返回的boolean类型只能是true或者false不能跟1进行==比较吧,改成
var
pages=confirm(
"choose to close the window"
);
if
(pages){
mywin.close();
alert(
"window has been closed"
);
}
else
{
alert(
"window has NOT been closed!"
);
}才有你想要的效果吧
JavaScript入门篇
739816 学习 · 9566 问题
相似问题