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
//HTML、CSS禁止选择文字,针对IE、FF、Chrome等 | |
<div unselectable="on" style="-moz-user-select:none;-webkit-user-select:none;" onselectstart="return false;"> | |
你选不了我, | |
unselectable: IE/Opera, | |
-moz-user-select: FireFox, | |
onselectstart: IE/Safari, | |
-webkit-user-select:Chrome | |
</div> |
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 preLoadImgs() { | |
var imgsUrl = [ | |
'../qhome/img/progress_1.png','../qhome/img/progress_1_1.png', | |
'../qhome/img/progress_2.png','../qhome/img/progress_3.png', | |
'../qhome/img/progress_4.png' | |
]; | |
for(var i in imgsUrl) { | |
preLoadImg(imgsUrl[i]); | |
} | |
} |
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
js判断是否为IE的办法 | |
1.+[1,] | |
2.!+"\v1" | |
3.!!(window.attachEvent && navigator.userAgent.indexOf('Opera') === -1) | |
4.!!(!window.addEventListener&& navigator.userAgent.indexOf('Opera') === -1) | |
5.!!(document.all && navigator.userAgent.indexOf('Opera') === -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
<html> | |
<head> | |
<script type="text/javascript"> | |
var count = 10; | |
function Picture() | |
{ | |
if (event.wheelDelta >= 120) | |
Resize(++count); | |
else if (event.wheelDelta <= -120) | |
Resize(--count); |
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 setKeyboardEvents() { | |
$(document).keydown(function(event) { | |
if(event.keyCode == 37){ | |
doSomething(); | |
} | |
else if (event.keyCode == 39){ | |
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
function jsonToString(obj){ | |
var THIS = this; | |
switch(typeof(obj)){ | |
case 'string': | |
return '"' + obj.replace(/(["\\])/g, '\\$1') + '"'; | |
case 'array': | |
return '[' + obj.map(THIS.jsonToString).join(',') + ']'; | |
case 'object': | |
if(obj instanceof Array){ | |
var strArr = []; |
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 + ')'); | |
} |
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
/** | |
* 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
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]; |