Skip to content

Instantly share code, notes, and snippets.

View hehongwei44's full-sized avatar
🎯
Focusing

kevin hehongwei44

🎯
Focusing
View GitHub Profile
@hehongwei44
hehongwei44 / type.js
Created July 9, 2014 14:05
变量的类型检查方式
/**
*
* js的类型检测方式->typeof、constuctor。
* 推荐通过构造函数来检测变量的类型。
*/
var obj = {key:'value'},
arr = ["hello","javascript"],
fn = function(){},
str = "hello js",
num = 55,
@hehongwei44
hehongwei44 / fistLetterUpper.js
Created July 10, 2014 06:25
将单个字符串的首字母大写
/**
*
* 将单个字符串的首字母大写
*
*/
var fistLetterUpper = function(str) {
return str.charAt(0).toUpperCase()+str.slice(1);
};
console.log(fistLetterUpper('hello')); //Hello
console.log(fistLetterUpper('good')); //Good
@hehongwei44
hehongwei44 / demo02.html
Last active August 29, 2015 14:03
通过把父类的对象实例赋值给子类来实现原型式集成
<!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;
@hehongwei44
hehongwei44 / extend.js
Created July 11, 2014 06:50
JavaScript中的类继承
/**
* 把一个实例方法添加到一个类中
* 这个将会添加一个公共方法到 Function.prototype中,
* 这样通过类扩展所有的函数都可以用它了。它要一个名称和一个函数作为参数。
* 它返回 this。当我写一个没有返回值的方法时,我通常都会让它返回this。
* 这样可以形成链式语句。
*
* */
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
@hehongwei44
hehongwei44 / default.css
Created July 15, 2014 02:12
去掉IE10默认的input样式
/**
*
* @link: http://1.hehongwei44.sinaapp.com/?p=283
*
*/
input::-ms-clear { display: none; } //去掉input中的叉叉
input::-ms-reveal { display: none; } //去掉密码框中的小眼睛
@hehongwei44
hehongwei44 / default.css
Last active August 29, 2015 14:03
去除chrome等浏览器默认的外边框
/**
*
* @link : http://1.hehongwei44.sinaapp.com/?p=207
*
*/
body, textarea, input, button, select, keygen, legend {
outline:none;
}
@hehongwei44
hehongwei44 / UseraAgent.js
Created July 15, 2014 03:28
用户代理的一些小技巧
/*
* @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');
@hehongwei44
hehongwei44 / domhelp.js
Created July 17, 2014 05:49
清楚节点内的空格
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);
@hehongwei44
hehongwei44 / domMethod.js
Last active August 29, 2015 14:04
dom一些常用的操作方法介绍
//查找相关元素的前一个兄弟元素的方法。
function prev(elem) {
do {
elem = elem.previousSibling;
} while (elem && elem.nodeType != 1);
return elem;
}
//查找相关元素的下一个兄弟元素的方法。
function next(elem) {
@hehongwei44
hehongwei44 / extendHTMLElement.js
Created July 17, 2014 09:00
通过原型拓展来实现DOM的查找方法。
//查找相关元素的前一个兄弟元素的方法。
HTMLElement.prototype.prev = function () {
var elem = this;
do {
elem = elem.previousSibling;
} while (elem && elem.nodeType != 1);
return elem;
};