(017)闭包

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5     <title>闭包</title>
 6     <script type="text/javascript">
 7 
 8         window.onload = function() {
 9 
10             function a() //父函数
11             {
12                 var num = 123;
13                 function b() //子函数 子函数可以是用父函数的局部变量
14                 {
15                     alert(num);
16                 }
17                 b();
18             }
19             a();
20         };
21         
22     </script>
23 </head>
24 
25 <body>
26     <input id="txt1" type="text"/>
27     <input id="txt2" type="text"/>
28     <input id="btn1" type="button" value="求和"/>
29 </body>
30 </html>

 

posted @ 2014-01-21 23:51  雪中飞雁  阅读(54)  评论(0)    收藏  举报