Math内置对象

1,圆周率

  Math.PI

2,最大值

  Math.max()

3,最小值

  Math.min()

4,  取整

1,  向上取整,取最大

  Math.ceil()

2,   向上取整,取最小

  Math.floor()

3,   四舍五入

  Math.round

5, 随机数,返回一个0-1之间的数

  Math.random() 

----------------------------------------------------------------------

随机生成一个rgb

rgb(0,0,0)每一项取值范围0-255

var r = parseInt(Math.random()*256)

var g = parseInt(Math.random()*256)

var b = parseInt(Math.random()*256)

var str = 'rgb(' + r +',' + g + ',' + b +')'

setInterval (() {

  document.body.style.backgroundColor = str;

},1000)

猜你喜欢

转载自www.cnblogs.com/xiaoxiao95/p/12906176.html
今日推荐