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
排序算法 | |
1、冒泡排序 | |
function bubbleSort(arr){ | |
var i = j = 0; | |
for(i=1; i<arr.length; i++){ | |
for(j=0; j<=arr.length-i; j++){ | |
var temp = 0; | |
// ">" 从小到大排序 |
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 str = "今天是星期" + "日一二三四五六".charAt(new Date().getDay()); |
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
/** | |
* 洗牌算法: | |
* 1. 从第一张牌开始,将每张牌和随机的一张牌进行交换 | |
* 2. 更优解法:从第一张牌开始,将每张牌和之前全部牌中随机的一张进行交换 | |
* 3. C++ 标准库函数 std::random_shuffle (原理与第一点差不多) | |
*/ | |
//inspired by http://www.cs.princeton.edu/~rs/ | |
function shuffle(arr) { | |
var len = arr.length, 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
var a = 0, b = true; | |
switch(true) { | |
case a: | |
alert('a'); | |
break; | |
case b: | |
alert('b'); | |
break; | |
} |
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
// 原生JavaScript获取复选框的值 | |
function get_checkbox_value(field){ | |
if(field&&field.length){ | |
for(var i=0;i<field.length;i++){ | |
if(field[i].checked && !field[i].disabled){ | |
return field[i].value; | |
} | |
} | |
}else { | |
return; |
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 func() { | |
var i = 0; | |
return function () { | |
return i++; | |
} | |
} | |
var counter = func(); | |
console.log(counter()); // 0 | |
console.log(counter()); // 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
var getNow = (function () { | |
//DEBUG 为false则返回真实时间,ture 则返回模拟时间。 | |
var DEBUG = true; | |
//通过修改年、月、日 时 分 秒 毫秒 来达到某个时间的模拟。 | |
var now = new Date(2014, 10, 24, 0, 0, 0, 0).getTime(); | |
var begin = new Date(); | |
return function () { | |
if (DEBUG) { | |
var t = new Date().getTime(); | |
now += t - begin; |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>圣诞树</title> | |
<style type="text/css"> | |
#innter{text-align: center;} | |
</style> | |
</head> | |
<body> |
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
<!DOCTYPE html> | |
<head> | |
<style type="text/css"> | |
*{ padding:0px; margin:0px;} | |
.box{ width:1000px; background:#ccc; margin:0 auto; overflow:hidden; margin-bottom:20px;} | |
.main{ width:770px; height:2000px; background:#000; float:left;} | |
.sub{ width:220px; background:#FC6; float:right;} | |
.sub01{ width:220px; height:100px; background:#0CC; margin-bottom:10px;} |
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 numToChar(str) { | |
var chartArr = str.split(""); | |
var chartLib = { | |
a: 1, | |
b: 2, | |
c: 3, | |
d: 4, | |
e: 5, | |
f: 6, | |
g: 7, |
NewerOlder