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 ua = navigator.userAgent; | |
isAndroid = /Android/i.test(ua); | |
isBlackBerry = /BlackBerry/i.test(ua); | |
isWindowPhone = /IEMobile/i.test(ua); | |
isIOS = /iPhone|iPad|iPod/i.test(ua); | |
isMobile = isAndroid || isBlackBerry || isWindowPhone || isIOS; | |
if(isAndroid) isMobile = 'android'; | |
if(isBlackBerry) isMobile = 'BlackBerry'; |
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
if (window.attachEvent) { | |
window.attachEvent("onload", remove); | |
} else if (window.addEventListener) { | |
window.addEventListener("load", remove, 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
$.ajax({ | |
url: url_preLogin, | |
async: false, | |
type: "GET", | |
data: preData, | |
success: callback | |
}); |
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 flag = false; | |
function change() { | |
flag = !flag | |
if (flag) { | |
// doSomething... | |
} | |
else { | |
// doSomething... | |
} | |
} |
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
/** | |
* Get domain name from url | |
* eg: 'http://123.blog.163.com/123/123.html' | |
*/ | |
getDomainName = function(url_str) { | |
return url_str.match(/(\w+\.(?:com|cn|net|org|cc|so|be|me|io|edu|gov|info|tv|museum|coop|aero| | |
int|biz|name|pro|aero|travel|jobs|mobi|jp|hk))(?:\/|$)/)[1]; | |
} |
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 cutRedundant(arr){ | |
for(var i=0;i<arr.length;i++) | |
for(var j=i+1;j<arr.length;j++) | |
if(arr[i]===arr[j]){arr.splice(j,1);j--;} | |
return arr.sort(function(a,b){return a-b}); | |
} | |
调用方法: | |
a=[1,2,2,3,4,5,5]; |
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
/** | |
* Check whether an item is in an array. | |
* @param {Obj} item | |
* @param {Array} array | |
* @return {Boolean} | |
*/ | |
contains = function(item, array) { | |
for(var i in array) { | |
if(array[i] === item) { | |
return true; |
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
滚动条 | |
当前高度 | |
window.scrollY | |
最大高度[2] | |
document.documentElement.scrollHeight - document.documentElement.clientHeight //所有现代浏览器,标准模式。火狐在混杂模式下为 0。2013年7月21日 | |
window.scrollMaxY //火狐,2013年7月21日 | |
document.height - window.innerHeight //Chrome | |
document.body.scrollHeight //Chrome,2013年7月21日 | |
document.documentElement.clientHeight //火狐,标准模式。2013年7月21日 |
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 stringToJSON(obj){ | |
return eval('(' + obj + ')'); | |
} |
NewerOlder