随笔分类 - javascript
摘要:JavaScript 是弱类型语言变量在条件语句中会根据期望值自动转换.关系运算false,'',null,undefined,0,NaN这6个在关系运算是都等于false其中 NaN (Not a number) 比较奇特, NaN ==false 结果为false, !!NaN转换结果是false;逻辑运算逻辑运算符号+,-,*, /,%-,*,/ 期望值都为数字,如果有一个或者两个不是数字,结果将是NaN+ 不一样, 只要两个运算值中有一个或者两个值为字符串,将作为连接符号使用.两个值都是数值时才执行加运算.5 +'5' // '55' f
阅读全文
摘要:第一章认识JavaScriptJavaScript特性: 1.面向对象编程的语言.function Person(name,age){ this.name = name; this.age = age;}Person.prototype.getName = function(){ return this.name;};Person.prototype.getAge = function(){ return this.age;};var p1 = new Person('John',30);var p2 = new Person('Bob',40);console
阅读全文
摘要:变量变量是存储数据的容器变量的定义与赋值JavaScript变量名区分大小写var name; //只声明var age = 20; //声明并赋值var dog = 10; // dog 和 Dog 和 DOG 不相等单var声明模式var a,b='apple',c =10; //单var关键字,多变量var age = 28, name = 'Bob', fly = true;变量的类型var undef = undefined; // undefined类型var num = 10; // number 类型var str = 'tree'
阅读全文
摘要:Selection对象,表示当前激活的高亮文本选区.Selection对象获取标本浏览器 : window.getSelection();IE : document.selection;兼容代码:var selection = window.getSelection ? window.getSelection() : document.selection;Selection对象取消选区if(selection.removeAllRanges){ selection.removeAllRanges();} else{ selection.empty();}
阅读全文
摘要:元素拖动前提条件:元素为定位元素, 个人建议position:absolute;算法1var left,top,x,y;var element = document.getElementById('drag');element.onmousedown = function(e){ e = e || window.event; left = this.offsetLeft; top = this.offsetTop; x =e.clientX; y =e.clientY; this.addEventListener('mousemove',dragMove,fal
阅读全文
摘要:Event兼容性代码,按照W3C标准兼容:var fixEvent = function(e){ e = e || window.event; if(!e.preventDefault){ e.preventDefault = function(){ event.returnValue = false; }; } if(!e.stopPropagation){ e.stopPropagation = function(){ event.cancelBubble = true; }; } if(e.pageX === undefined && e.pag...
阅读全文

浙公网安备 33010602011771号