[Javascript]Js學習筆記

Allen
NoteOcean
Published in
Dec 20, 2020

紀錄線上課程中,提到的方法

1.利用JS在HTML中建立tag
例:建立table TAG

var table=document.createElement("table")

2.在JS中,獲取HTML中的TAG物件,並使用
例:獲取table(id=TableID)物件

var table=document.getElementById("TableID")

3.插入物件到現有的HTML TAG中
利用2中的table 物件,插入一個TH TAG

table.append(th)

4.利用JS做HTML TAG寫入

var th=document.getElementById("th")
th.innerHTML=這裡填入想寫入的值

5.JS中所有物件都會被掛在WINDOW下
可以用console.log(window)查看內部有那些東西

console.log(window)
console.log(window.document)#常用

6.利用JS監聽目前HTML變動
監聽divInput的輸入,並匯出到console中

divInput.addEventListener(input,function(e){
console.log(e)
})

7.JS this的使用
this指當前物件,但物件中的物件沒辦法用this去做物件的擷取,可以使用
bind來將物件中的function的function合併到外圍的環境中。

--

--