This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
$(".location").bind("input", function() { | |
var $this = $(this); | |
var delay =250; // delay after last input | |
clearTimeout($this.data('timer')); | |
$this.data('timer', setTimeout(function(){ | |
$this.removeData('timer'); | |
doSomething(); | |
}, delay)); | |
}); |
This file contains hidden or 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
<A href="javascript:void(0)">click me</a> | |
//javascript:void(0) 不返回的意思 |
This file contains hidden or 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
//使用return false来禁用 form的默认submit事件。 | |
<form method="POST" action="" id="search-form"> | |
<input type="text" name="keywords" /> | |
<input type="submit" value="Search" id="sButton" onclick="loadXMLDoc('file.xml')" /> | |
</form> | |
<script> | |
window.onload = function() { | |
document.getElementById("search-form").onsubmit = function() { |
This file contains hidden or 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 timestamp = Date.parse(new Date()); | |
结果:1280977330000 | |
第二种方法: | |
var timestamp = (new Date()).valueOf(); |