ITeye博客

javaScript

共 11 篇文章

javascript中使用模块化规避缺陷

//使用模块化规避缺陷 //alert("test"); String.prototype.findx=function(){ var entity={ quot:'"', lt:'<', gt:'>' }; return function(){ var temp=""; this.replace(/&([\w]+);/g,function(a,b,c){ var r=entity[b]; console.info("a: "+a+" "+"b: "+b+" "+"c: "+c); typeof r==="string" ?r:a; temp+=r; }); return temp; }; …

2015-05-31 10:43 · javaScript

javascript中函数实现历史记录

//使用函数实现历史记录 //alert("test"); //例子 var f=function(n){ return n<2 ? n: f(n-1)+f(n-2); }; //console.info(f(5)); //console.info(f(6)); var i=1; while(i<=10){ console.info(f(i)); i++; } var memory=function(arr,func){ var recur=function(n){ var result=arr[n]; if(typeof(result) !=="number"){ result=func(…

2015-05-31 10:41 · javaScript

javascript数组的一些奇葩

//alert("test"); //javascript 中数组不一样的用法 var a=[]; a[-1]=1; console.info(a.length); //0 console.info(a[-1]); //1 console.info(a["-1"]); //1 说明这个值以对象属性的形式被存储 a[true]=2; console.info(a[true]); //值为1 console.info(a[1]); //这个地方true 不能再转换为1 //再做一个另类的测试 var a1=[]; a1[0,0]=1; a1[0,1]=2; console.info(a1.len…

2015-05-31 10:35 · javaScript

javaScript拖拽原理的分析与实现

<script type="text/javascript"> window.onload=function(){ var oDiv=document.getElementById('box1'); //console.info(getPos(oDiv).leftX);//测试可以 //三个事件 //兼容性没有做判断 //通过以下两种可实现ie7及以下浏览器的兼容 //setCapture全局捕获 再释放捕获 //return false //以前两种可实现兼容性问题,并没有用浏览器做兼容实验 所用版本,chrome 40几来着记不清了 //也可做函数封装drag oDiv.onmoused…

2015-05-04 10:37 · javaScript

javaScript对冒泡做一些分析与测试

<script src="js/冒泡.js"></script> <script type=text/javascript> </script> <style> body{ margin:0px; padding:0px; } #div1{ width:300px; height:200px; background:#CC3; margin:30px auto 0px 10px; position:relative; } #div2{ width:300px; height:200px; background:#096; position:absolute; left:310px; } #d…

2015-04-30 11:06 · javaScript

javaScript中getElementByClassName的实现

<style> body{ margin:0px; padding:0px; } #div1{ width:300px; height:200px; background:#CC3; margin:30px auto 0px 10px; position:relative; } #div2{ width:300px; height:200px; background:#096; position:absolute; left:310px; } #div11{ margin-left:10px; } </style> </head> <body> <div id='div1' class='d…

2015-04-28 17:00 · javaScript

javaScript 元素的位置,尺寸,宽度总结下

<style> body{ margin:0px; padding:0px; } #div1{ width:300px; height:200px; background:#CC3; margin:30px auto 0px 10px; position:relative; } #div2{ width:300px; height:200px; background:#096; position:absolute; left:310px; } #div11{ margin-left:10px; } </style> </head> <body> <div id='div1'> xxxxxx …

2015-04-28 14:54 · javaScript

javaScript 元素的位置,尺寸,宽度总结上

<style> body{ margin:0px; padding:0px; } #div1{ width:300px; height:200px; background:#CC3; margin:30px auto 0px 10px; position:relative; } #div2{ width:300px; height:200px; background:#096; position:absolute; left:310px; } #div11{ margin-left:10px; } </style> </head> <body> <div id='div1'> xxxxxx …

2015-04-28 14:41 · javaScript

javaScrpt DOM分析与实战

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test2</title> <link href="css/cssDom.css"/> <scri…

2015-04-27 15:44 · javaScript

javaScript作用域分析

<script type=text/javascript> // 作用域分析分为两部分 //预解析 //执行代码 //先上一个 var a=1; function f1(){ alert(a);//undefined var a=2; } f1(); alert(a);//1 //预解析 (全局变量) //全局a=undefined; 解析的时候只是将变量放到全局的仓库里 //函数f1=function f1(){} //解析完,执行语句 //a=1; //执行到函数,函数也有作用域,再来用同样方法 //局部 var a=undefined; //执行代码 //a=2; //所以结果吗写在代…

2015-04-26 17:08 · javaScript

javaScript之数组

//测试Chrome版本 40.0.2214.115 m //如有问题,欢迎指出 //=====数组的声明方式 有两种 //对数组的一些常用方法进行深入 //var arr1=new Array[3];//数组的长度 //这是错误的 var arr1=new Array(3); var arr2=new Array(3,2,3,5); var arr3=new Array([1,2,3,4],[1,2,3],[1,2]); //字面量 var arr4=[[2,3],[2],[0]]; //console.info(arr1); //console.info(arr2); //console…

2015-04-20 16:57 · javaScript