This file contains 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() { | |
var newScript, load, | |
firstScriptTag = document.getElementsByTagName('script')[0]; | |
load = function load(url) { | |
newScript = document.createElement('script'); | |
newScript.async = true; | |
newScript.src = url; | |
firstScriptTag.parentNode.insertBefore(newScript, firstScriptTag); |
This file contains 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 QueryStringToJSON() { | |
var pairs = location.search.slice(1).split('&'); | |
var result = {}; | |
pairs.forEach(function(pair) { | |
pair = pair.split('='); | |
result[pair[0]] = decodeURIComponent(pair[1] || ''); | |
}); | |
return JSON.parse(JSON.stringify(result)); |
This file contains 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
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and ( min--moz-device-pixel-ratio: 1.5), only screen and ( -o-min-device-pixel-ratio: 3/2), only screen and ( min-device-pixel-ratio: 1.5), only screen and (min-resolution: 192dpi) { | |
/* Style Rules */ | |
} |
This file contains 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 parseURL(url) { | |
var a = document.createElement('a'); | |
//创建一个链接 | |
a.href = url; | |
return { | |
source: url, | |
protocol: a.protocol.replace(':',''), | |
host: a.hostname, | |
port: a.port, | |
query: a.search, |
This file contains 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 addEvent,removeEvent; | |
addEvent = function(elm, evType, fn, useCapture) { | |
if (elm.addEventListener) { | |
elm.addEventListener(evType, fn, useCapture);//DOM2.0 | |
return true; | |
}else if (elm.attachEvent) { | |
var r = elm.attachEvent('on' + evType, fn);//IE5+ | |
return r; | |
}else { |
This file contains 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 toggle(obj) { | |
var el = document.getElementById(obj); | |
if ( el.style.display != 'none' ) { | |
el.style.display = 'none'; | |
} | |
else { | |
el.style.display = ''; | |
} | |
} |
This file contains 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
Array.prototype.inArray = function (value) { | |
for (var i=0,l = this.length ; i <l ; i++) { | |
if (this === value) { | |
return true; | |
} | |
} | |
return false; | |
}; |
This file contains 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
// 通过isEqual工具方法判断数值是否相等 | |
function isEqual(number1, number2, digits){ | |
digits = digits === undefined? 10: digits; // 默认精度为10 | |
return number1.toFixed(digits) === number2.toFixed(digits); | |
} | |
isEqual(1.0-0.7, 0.3); // return true | |
// 原生扩展方式,更喜欢面向对象的风格 | |
Number.prototype.isEqual = function(number, digits){ |
This file contains 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
document.getElementById("myelement").addEventListener("click", handler); | |
// 处理器函数 | |
function handler(e) { | |
// 移除处理器 | |
e.target.removeEventListener(e.type, arguments.callee); | |
alert("You'll only see this once!"); | |
} |
OlderNewer