摘要: 总结了几个在学习工作中碰到的,做下记录,也欢迎大家指证,补充.1.在判断typeof x=='undefined'时,可以采用typeof x>'t'代替,比较一个字母比逐字比较更快.2.if(x){a=0},最简单的if语句,如果X存在则给a赋值,可用x&&a=0;代替,处理关系运算符比条件运算符更快.3.for循环,i--比i++更快.4.变量转换的快速方法:var myVar = "3.14159",str = ""+ myVar,// to stringint = ~~myVar, // to 阅读全文
posted @ 2012-11-08 16:22 zwei1989 阅读(1005) 评论(0) 推荐(1) 编辑
摘要: 阅读全文
posted @ 2014-03-18 15:58 zwei1989 阅读(4723) 评论(0) 推荐(1) 编辑
摘要: baidu下一堆博文说new Function比eval要来的高效,一直有个疑惑,都是重新编译一遍js,new Function还要多执行一部函数,为什么new会更高效?上代码先<script type="text/javascript"> var str='[{"打算": "aa","反倒是": "dasd","的撒": "dasd","事项": [{"事项": "gdf", 阅读全文
posted @ 2013-04-02 13:00 zwei1989 阅读(1777) 评论(2) 推荐(0) 编辑
摘要: eval("var str = '"+JSON.stringify(obj)+"';");document.write(str);原理是利用JS再做了一层解析,把unicode又变成中文。 阅读全文
posted @ 2013-03-14 18:28 zwei1989 阅读(3443) 评论(1) 推荐(1) 编辑
摘要: document.documentElement.getBoundingClientRect例:doucment.getelementById('a').getBoundingClientRect();有4个方法,top, right, bottom ,left 分别返回被选取元素每条边距离浏览器左和上的距离。理论上是这个样的dom.getBoundingClientRect().left+dom.offsetWidth==dom.getBoundingClientRect().right; 阅读全文
posted @ 2012-12-13 16:38 zwei1989 阅读(246) 评论(0) 推荐(0) 编辑
摘要: 1、先来看淘宝无线wiki要求在页面中添加的meta标签。<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" /><meta content="yes" name="apple-mobile-web-app-capable" /><meta content="black" name="apple- 阅读全文
posted @ 2012-12-12 17:33 zwei1989 阅读(4555) 评论(0) 推荐(0) 编辑
摘要: function Carousel(id,num,prev,next,li_width){ var oBox=document.getElementById(id); this.aLi=oBox.getElementsByTagName('li'); this.n=num; this.Width=li_width; this.prev=document.getElementById(prev); this.next=document.getElementById(next); for(var i=0;i<this.aLi.length;i++){ ... 阅读全文
posted @ 2012-12-06 16:06 zwei1989 阅读(281) 评论(0) 推荐(0) 编辑
摘要: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>CSS3 3D场景展示</title> <style type="text/css"> body { background-color: #D42FA0; font-size: 12px; } #content { width: 100%; he 阅读全文
posted @ 2012-12-05 14:38 zwei1989 阅读(2310) 评论(0) 推荐(0) 编辑
摘要: 声明NodeFilter在IE中不能使用第一种方法:使用NodeIterator可以用document对象的createNodeIterator()方法来创建NodeIterator对象,基本形式如下:var iterator = document.createNodeIterator(root, whatToShow, filter,entityReferenceExpansion);用到的四个参数意义如下:1、root:从树中的哪个节点开始搜索;2、whatToShow:一个数值代码,代表哪些节点需要搜索;3、filter:NodeFilter对象,用来决定需要忽略哪些节点;4、entit 阅读全文
posted @ 2012-11-28 13:19 zwei1989 阅读(5603) 评论(1) 推荐(2) 编辑
摘要: 以一个<p>标签元素举例,其向上寻找原型对象用过会是这样:HTMLParagraphElement.prototype→HTMLElement.prototype→Element.prototype→Node.prototype→Object.prototype 阅读全文
posted @ 2012-11-14 15:52 zwei1989 阅读(169) 评论(0) 推荐(0) 编辑