代码: 输出结果 补充: reg.lastIndex:下一次正则捕获的开始查找的索引位置 ->正则的懒惰性就是因为默认情况下lastIndex值都是0,我们不管执行几次exec,都是从字符串的开始位置查找,那么每一次捕获到的都是第一个符合的内容 Read More
posted @ 2016-02-19 17:44 __sarah Views(372) Comments(0) Diggs(0) Edit
1、通过CSS来实现 1) position: absolute; top:50%; left:50%; margin-left:-101px; margin-top:-101px; 2) position:absolute; left:0; top:0; right:0; bottom:0; ma Read More
posted @ 2016-02-19 14:19 __sarah Views(5866) Comments(0) Diggs(1) Edit
函数中的this指向和当前函数在哪定义的或者在哪执行的都没有任何的关系分析this指向的规律如下:[非严格模式]1、自执行函数中的this永远是window [案例1] var obj={ fn:(function(i){ //this->window return function(){ //th Read More
posted @ 2016-02-16 18:45 __sarah Views(1008) Comments(0) Diggs(0) Edit
<!DOCTYPE html> /*直接复制代码即可在浏览器验证*/<html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style> * { margin: 0; padding: 0; } /*盒子的样式*/ .box { Read More
posted @ 2016-01-29 22:37 __sarah Views(820) Comments(0) Diggs(0) Edit
utils class v1.0:The common methods used in our JS are included. * by sarah on 2016/01/28var utils = { //listToArray:将类数组转换为数组 listToArray: function l Read More
posted @ 2016-01-28 11:33 __sarah Views(994) Comments(0) Diggs(0) Edit
1、typeof 用来检测数据类型的运算符->typeof value->返回值首先是一个字符串,其次里面包含了对应的数据类型,例如:"number"、"string"、"boolean"、"undefined"、"object"、"function"->局限性:1)typeof null ->"o Read More
posted @ 2016-01-28 10:33 __sarah Views(8603) Comments(1) Diggs(0) Edit
1、JS中的定时器有两种: window.setTimeout([function],[interval]) 设置一个定时器,并且设定了一个等待的时间[interval],当到达时间后,执行对应的方法[function],当方法执行完成定时器停止(但是定时器还在,只不过没用了);window.set Read More
posted @ 2016-01-27 22:29 __sarah Views(253355) Comments(3) Diggs(7) Edit
//->自己在内置类的原型上扩展一个myForEach来处理forEach不兼容的问题//callBack:回调函数,遍历数组中的一项,就要执行一次callBack//context:改变callBack方法中的this指向 Array.prototype.myForEach = function Read More
posted @ 2016-01-27 21:38 __sarah Views(9887) Comments(0) Diggs(0) Edit
1、使用递归思想实现setTimeout的轮询动画:在每一次执行方法的时候都重新的设置一个定时器,然后在指定时间内重新的执行当前的方法 问题:每一次设置的定时器,虽然不执行了,但是还存在呢,浪费性能 ->在每一次执行方法的时候首先把上一次创建的定时器清除掉 [案例] var timer = null Read More
posted @ 2016-01-27 21:00 __sarah Views(1544) Comments(0) Diggs(0) Edit