clinna
2017-04-22 01:20
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>javascript</title> <script type="text/javascript"> function context() { var mychar="I love U!" alert(mychar); } function a1(){ var mywin=window.open("http://www.imooc.com" ,'_blank','width=300,height=200,menubar=no,toolbar=no, status=no,scrollbars=yes');} function a2(){ mywin.close(); } </script> </head> <body> <form> <input type="button" value="点击我" onclick="context()" /> <br> <input type="button" onclick="a1()" value="打开窗口" /> <input type="button" onclick="a2()" value="关闭窗口" /> </form> </body> </html>
浏览器火狐,打开就关不了
把mywin提取到方法外面,否则在a2()里面是访问不到a1()的mywin的
我看了你的代码 提取到外面不好使呀
<html> <head> <meta charset="UTF-8"> <title>javascript</title> <script type="text/javascript"> var mywin=window.open("http://www.imooc.com" ,'_blank','width=300,height=200,menubar=no,toolbar=no, status=no,scrollbars=yes'); function context() { var mychar="I love U!" alert(mychar); } function a1(){ mywin.open(); } function a2(){ mywin.close(); } </script> </head> <body> <form> <input type="button" value="点击我" onclick="context()" /> <br> <input type="button" onclick="a1()" value="打开窗口" /> <input type="button" onclick="a2()" value="关闭窗口" /> </form> </body> </html>
JavaScript入门篇
739817 学习 · 9566 问题
相似问题