JS 语法学习

0.语法
var StaticClazz = {   //static property and method
       name : "张三",
       show : function(){
            alert(this.name);
       }
       //this.show = function(){}
  }
  StaticClazz.show(); // 静态类不需要实例化
 
  function Emp(){
      this.name  = "李四";   //public property
      age = 10;             //private property
  }
 
  Emp.prototype  = {
      sex  : '男',
      show : function(){
        alert(this.name + " " +age);
      }
  }
 

  Emp.prototype.sex = "女";
 
  var emp = new Emp;
  alert("name: " + emp.name + " age: " + emp.age + " sex: " + emp.sex);
  emp.show(); 
 
  Emp.show3 = function(){
    alert("show3");
  }
  Emp.show3();
 
 //判断为空    
 function Utils(){
 }                  
 Utils.isEmpty = function(v, allowBlank)
 {
     return v === null || v === undefined
             || (!allowBlank ? v.trim().length === 0 : false);
 };

1.  在火狐下获得year需要+1900
 var x=navigator.appName;///判断浏览器的名称
 var date=new Date();
 var thisYear=date.getYear();
 if(x=='Netscape'){   //在火狐下获得year需要+1900
  thisYear+=1900;
 }
 

2. 点击其他地方隐藏弹出层
 jQuery(".showDivId").click(function(e){e.stopPropagation();})  //屏蔽其他事件
 
 jQuery("body").click(function(){
     jQuery(".showDivId").remove(); 
 });
 
3.遍历
  for ( var key in field.options) {}
 
4.获得body大小document.body.clientWidth

5.迭代 
for( var name in jsonObj) {
 
}

6.点击区域判断
 $(document).click(function(event){
      if ($(event.target).closest("#dropdown").length == 0){
          //隐藏对象操作
      }
  });
                       

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值