首页 > 代码库 > JS方法

JS方法

var time = new Date();
var year = time.getFullYear();
年份输出
var second = time.getSeconds();
秒的输出
var moth = time.getMonth()+1;
月份的输出
var day = time.getDay();
星期几
var day = time.getDate();
哪一天


document.write(time);


var rand = Math.random();
random 是随机数的意思

 

document.write(rand);
var arr = ["张三","李四","王五","赵六","七七"]
var shuzi =rand*arr.lenght;
document.write(shuzi);
是0到1的数,也就是概率
shuzi = parseInt(shuzi);
取整
document.write(arr[shuzi]);
随机数的转换


var i = 1.1;
i = math,round(i);
document.write
四舍五入

var i = 1.1;
i = Math.ceil(i);
向上取整
i = Math.floor(i);
向下取整
document.write(i);

JS方法