您的位置:首页 > Web前端 > JavaScript

JS 语法学习

2013-03-11 14:55 120 查看
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){

//隐藏对象操作

}

});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: