This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * | |
| * js的类型检测方式->typeof、constuctor。 | |
| * 推荐通过构造函数来检测变量的类型。 | |
| */ | |
| var obj = {key:'value'}, | |
| arr = ["hello","javascript"], | |
| fn = function(){}, | |
| str = "hello js", | |
| num = 55, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * | |
| * 将单个字符串的首字母大写 | |
| * | |
| */ | |
| var fistLetterUpper = function(str) { | |
| return str.charAt(0).toUpperCase()+str.slice(1); | |
| }; | |
| console.log(fistLetterUpper('hello')); //Hello | |
| console.log(fistLetterUpper('good')); //Good |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head lang="en"> | |
| <meta charset="UTF-8"> | |
| <title>js继承</title> | |
| </head> | |
| <body> | |
| <script type="text/javascript"> | |
| function Person(name) { | |
| this.name = name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 把一个实例方法添加到一个类中 | |
| * 这个将会添加一个公共方法到 Function.prototype中, | |
| * 这样通过类扩展所有的函数都可以用它了。它要一个名称和一个函数作为参数。 | |
| * 它返回 this。当我写一个没有返回值的方法时,我通常都会让它返回this。 | |
| * 这样可以形成链式语句。 | |
| * | |
| * */ | |
| Function.prototype.method = function (name, func) { | |
| this.prototype[name] = func; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * | |
| * @link: http://1.hehongwei44.sinaapp.com/?p=283 | |
| * | |
| */ | |
| input::-ms-clear { display: none; } //去掉input中的叉叉 | |
| input::-ms-reveal { display: none; } //去掉密码框中的小眼睛 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * | |
| * @link : http://1.hehongwei44.sinaapp.com/?p=207 | |
| * | |
| */ | |
| body, textarea, input, button, select, keygen, legend { | |
| outline:none; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * @link :http://browserhacks.com/ | |
| * IE篇 | |
| */ | |
| var isIE = document.all && !window.XMLHttpRequest; //IE6为true,其他都为false | |
| var isIE = !!window.ActiveXObject; //ie6-10都为true, | |
| var isIE = document.all && document.compatMode; //ie6-10都为true, | |
| /*返回IE6-9的版本号*/ | |
| var _IE = (function(){ | |
| var v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function cleanWhitespace(element) { | |
| //如果不提供参数,则处理整个HTML文档 | |
| element = element || document; | |
| //使用第一个节点作为开始指针 | |
| var cur = element.firstChild; | |
| //一直循环,直到没有子节点为止。 | |
| while (cur != null) { | |
| //如果节点是文本节点,并且只包含空格 | |
| if ((cur.nodeType == 3) && !/\S/.test(cur.nodeValue)) { | |
| element.removeChild(cur); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //查找相关元素的前一个兄弟元素的方法。 | |
| function prev(elem) { | |
| do { | |
| elem = elem.previousSibling; | |
| } while (elem && elem.nodeType != 1); | |
| return elem; | |
| } | |
| //查找相关元素的下一个兄弟元素的方法。 | |
| function next(elem) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //查找相关元素的前一个兄弟元素的方法。 | |
| HTMLElement.prototype.prev = function () { | |
| var elem = this; | |
| do { | |
| elem = elem.previousSibling; | |
| } while (elem && elem.nodeType != 1); | |
| return elem; | |
| }; |