Skip to content

Instantly share code, notes, and snippets.

//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>
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]);
}
}
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)
<html>
<head>
<script type="text/javascript">
var count = 10;
function Picture()
{
if (event.wheelDelta >= 120)
Resize(++count);
else if (event.wheelDelta <= -120)
Resize(--count);
function setKeyboardEvents() {
$(document).keydown(function(event) {
if(event.keyCode == 37){
doSomething();
}
else if (event.keyCode == 39){
doSomething();
}
});
}
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 = [];
function stringToJSON(obj){
return eval('(' + obj + ')');
}
滚动条
当前高度
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日
/**
* 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;
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];