Javascript杂记(一)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>

  <p id="aa">123</p>
	<script type="text/javascript">
	     

	     var b=2;
	     var c;  //声明的作用会给该变量预留下存储的内存空间,使其值具有undefined的基础值,不经声明的变量在使用时默认为不存在(只有赋值语句时默认为全局下变量)
         var a=c||b;  //a会逐个匹配,遇到null、0、undefined值会跳过
         console.log(a);


         var demo=document.getElementById("aa");
         console.log(demo);
         demo.onclick=function(e){  //事件触发函数会产生一个排在首位的参数,默认为此dom上的事件对象
         var e=e||window.event;  //老版本IE,事件对象放到了全局命名空间下。也就是window属性上,这句话可以兼容所有浏览器 
          }

       
          function fn1(){
            /* demo.onmouseover=function(){alert(2);}*/
          	(function(){  //闭包格式的匿名函数相当于静态方法,在dom事件绑定的后面会报错,建议写在前面
         	   alert(1);
               fn1_1(4,5);  //通过在匿名函数中调用带参数的函数,可以实现匿名函传参的效果
              })();

              function fn1_1(x1,x2){  
                alert(x1+x2);
              }
           }
          
          fn1();

	</script>
</body>
</html>



           

  

原文地址:https://www.cnblogs.com/zhu-xingyu/p/5286531.html