2015/7/14
array:
var arr = new Array(1, 2, 3);
var arr1 = new Array("a", "b", "c");
var arr2 = new Array(true, true, true);
//往数组的末尾添加值,可以是一个或者多个值,中间通过,分隔;
alert(arr.push(4, 5));
//连接数组元素,中间有分隔符;
var str = arr.join(" ");
alert(str);
//颠倒数组的顺序,是操作本身;
alert(arr.reverse());
//增加删除元素
var arr = new Array(6);
arr[0] = "George";
arr[1] = "John";
arr[2] = "Thomas";
arr[3] = "James";
arr[4] = "Adrew";
arr[5] = "Martin";
arr.splice(0,1, "test");
alert(arr);
连接两个或多个数组
alert(arr.concat(arr1, arr2));
isNaN:
<input id="txt" type="text"/>
<input id="btn" type="button" value="点我"/>
<script type="text/javascript">
var txt = document.getElementById("txt");
var btn = document.getElementById("btn");
btn.onclick = function () {
if(!isNaN(txt.value)) {
var num = parseInt(txt.value);
alert(num * num);
} else {
alert("请输入合法的数字!!");
}
math
//最大值
var max = Math.max(1, 2, 3);
// alert(max);
//最小值
var min = Math.min(1, 2, 3);
// alert(min);
// var r = Math.random();
var r = parseInt(Math.random() * 1000);
alert(r);
var r1 = Math.round(4.1);
alert(r1);
输出日期:
var today = new Date();
var year = today.getFullYear();
var month = today.getMonth();
var day = today.getDate();
var hours = today.getHours();
var mins = today.getMinutes();
var s = today.getSeconds();
var str = year + "年" + (month + 1) + "月" + day + "日" + hours;
alert(str);