js 5--24 數(shù)學(xué)對象和Dom增加元素

一、數(shù)學(xué)對象

求最大值:Math.max(1,2,3,4,5);

求最小值:Math.min(1,2,3,4,5);

求數(shù)組中的最大值和最小值:

Math.min.apply(null,[ ]);//最小值

Math.max.apply(null,[ ]);//最大值

Math.ceil(15.66);向上取整//16

Math.floor(14.9);向下取整//14

Math.random( );輸出0-1之間的隨機數(shù),不包含0和1

Math.floor(Math.random( )*(max-min+1)+min);//求最大值和最小值兩個數(shù)之間的隨機數(shù)

二、日期對象

//聲明一個日期? ? 同時也是獲取系統(tǒng)的當(dāng)前時間

var date=new Date( );

//自定義一個時間

var date=new Date(yy/MM//dd hh:mm:ss)

? ? ? ? ? ? ? ? ? ? ? 年/月/日 時:分:秒

日期對象的API:

年 : FullYear 月 : Month 日 : Date

星期 : Day 時 : Hours 分 : Minutes

秒 : Seconds 毫秒 : Milliseconds

三、DOM

增加: 1.創(chuàng)建元素

var a=document.createElement('a');

2.給元素添加屬性或內(nèi)容:

a.GOTO BAIDU"

3.追加到DOM樹? 父元素.appendChild(子元素)

document.querySelector('div').appendChild(a);

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容