1、在枚举过程中,必须过滤掉那些不想要的值,具体方法有两个:一个是:使用hasOwnProperty方法过滤原型属性;另一个是使用 typeof 运算符排除方法函数。

例:

var name;
for(name in obj){
  if(typeof  obj[name]!=='function'){
            document.writeLn(name+":"+obj[name]);
    }  
}

 2、判断document文档加载完毕的方法:

function f(){
    if(document&&document.getElementsByTagName&&document.getElementsById&&document.body){
        clearIterval(timer);

        //执行JavaScript脚本
    }
}
vartime染色体Inter(f,10);

 3、arguments.callee,此值指向当前正在运行的匿名函数。

 4、获取不同浏览器的坐标值:

  posX=e.pageX||e.clientX+document.documentElement.scrollLeft+document.body.scrollLeft;

 5、获取指定元素距离窗口左上角的偏移坐标

  (body 和 html 没有offsetParent属性)

function getW(e){

    var  x=y=0;
    while(e.offsetParent){
          x+=e.offsetLeft;
          y+=e.offsetTop;
          e=e.offsetParent;
    }
    return {
        "x":x,
        "y":y
    }
}
获取指定元素距离包含块元素左上角的偏移坐标
function getB(e){
    return{
        "x":(parseInt(getStyle(e,"left"))||0),
        "y":(parseInt(getStyle(e,"top"))||0)
    }
}

  

  

posted on 2016-11-02 16:42  奋斗着的程序媛  阅读(153)  评论(0编辑  收藏  举报