console.log(Math.floor(25.6));//下取整25。
console.log(Math.ceil(25.4));//上取整26。
console.log(Math.random( ));//輸出0-1之間的隨機(jī)小數(shù)。
求隨機(jī)數(shù)max,min之間的隨機(jī)數(shù):
console.log(Math.floor(math.random()*(min-max+1)+max));
練習(xí):隨機(jī)變換顏色
setInterval(function(){
var div = document.querySelector('.box');
var r = Math.floor(Math.random() * (255));
var g = Math.floor(Math.random() * (255));
var b = Math.floor(Math.random() * (255));
div.style = 'background:rgb(' + r + ',' + g + ',' + b + ')';
console.log(r);
console.log(g);
console.log(b);
},100);