判断NaN | isNaN(x) |
停止页面的加载 | window.stop ? window.stop() : document.execCommand("Stop"); |
代替alert() | console.log(); |
获取浏览器的宽高 | function winHeight(){return window.innerHeight || document.documentElement.clientHeight; } function winWidth(){ return window.innerWidth || document.documentElement.clientWidth;} |
获取浏览器滚动条的top | function winScrolltop(){return document.documentElement.scrollTop || document.body.scrollTop;} |
禁止input缓存 | autocomplete="off" |
图片加载函数 | function imgload(url,callback){ var _img = new Image(); _img.src = url; if(_img.complete == false){ _img.onload = function(){ callback(); }; }else{ callback(); } } |
cssText | element.style.cssText |
DOMContentLoaded | (function() { var ie = !!(window.attachEvent && !window.opera), wk = /webkit\/(\d+)/i.test(navigator.userAgent) && (RegExp.$1 < 525); var fn = [], run = function() { for (var i = 0; i < fn.length; i++) fn[i](); }, d = document; d.ready = function(f) { if (!ie && !wk && d.addEventListener) { return d.addEventListener('DOMContentLoaded', f, false); } if (fn.push(f) > 1) return; if (ie)(function() { try { d.documentElement.doScroll('left'); run(); } catch(err) { setTimeout(arguments.callee, 0); } })(); else if (wk) var t = setInterval(function() { if (/^(loaded|complete)$/.test(d.readyState)) clearInterval(t),run(); },0); };})(); |
匿名函数写法 | 方法1: (function(){ })(); 方法2: ~function(){ }(); |
IE渲染模式强制调到最高 | <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
判断一个DOM是否为另一个的子集 | contains(); father.contains(child) |
手机站设置代码 | <meta name="viewport" content="width=640;initial-scale=1;minimum-scale=0.5;maximum-scale=0.5;user-scalable=yes"/> |
屏蔽复制,屏蔽右键菜单 | document.body.oncopy = function(){ return false}; document.oncontextmenu = function(){return false} |