### 事件
~~~
var test = document.getElementById("test");
test.onclick = function(){
~~~

var test 是節點
document.getElementById("test")獲取節點
this指執行事件的當前對象
~~~
this.style.color ="red";
~~~
點擊顏色變紅

~~~
this.innerHTML = "change"
~~~
點擊文字改變

~~~
if(this.style.color=="red"){
this.style.color="#333"
}else{
this.style.color="red"
}
~~~
點擊紅黑切換
~~~
this.style.color=(this.style.color==="red")?"#333":"red";
~~~
三目運算實現紅黑切換
三個等號表示連類型也完全一致
\[為真執行第一個指令,假執行冒號后的指令\]
- 第一章 git
- 1.1 git基本語法
- 1.2 版本回退
- 1.3 ssh的配置
- 第二章 markdown基本語法
- 第三章 HTML CSS
- 3.1 html基礎知識
- 3.2 css基礎
- 3.3 img垂直居中
- 3.4 清除鼠標懸停抖動
- 3.5 字體、列表、表格、文本、鏈接樣式
- 3.6 屬性繼承
- 3.7 float
- 3.8 定位
- 3.9 li加邊框文字移動問題
- 3.10 title旁邊的小圖標
- 第四章 Vue
- 4.1
- 第五章 JavaScript
- 5.1 基本語法
- 5.2 DOM事件
- 5.3 事件
- 5.4 jQuery引用
- 5.5 顯示與隱藏
- 5.6 回到頂部
- 第六章 jQuery
- 6.1 基礎語法