[TOC]
## 1.DOM事件(event)
> JavaScript與HTML之間的交互式通過事件實現的
### 1.1 onclick
> 點擊事件
### 1.2onfocus和onblur
~~~
<body>
<input type="text" id="txt">
<script>
var txt = document.getElementById("txt");
txt.onfocus=function(){
this.style.background="pink";
}
txt.onblur = function(){
this.style.background= "green";
}
</script>
</body>
~~~

#### 小項目:實現焦點拉長
~~~
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
~~~
~~~
<style>
input{
width: 200px;
height: 30px;
outline: none;
border-radius: 8px;
}
</style>
~~~
~~~
<body>
<input type="text" id="txt">
<script>
$("#txt").focus(function(){
$(this).animate({width:"300px"},1000)
})
$("#txt").blur(function(){
$(this).animate({width:"200px"},1000)
})
</script>
</body>
~~~

### 1.3 onmouseover和onmouseout
> onmouseover //鼠標移到某元素之上
onmouseout //鼠標從某元素移開
` <link href="https://cdn.bootcss.com/animate.css/3.5.2/animate.css" rel="stylesheet">
`
~~~
<body>
<p id="test" class="animated">hello world</p>
<script>
/*
onmouseover-->鼠標移入
onmouseout-->鼠標移除
*/
var test = document.getElementById("test");
test.onmouseover = function(){
this.classList.add("shake")
}
test.onmouseout = function(){
this.classList.remove("shake");
}
</script>
</body>
~~~

### 1.4onload
> 頁面加載時觸發
### 1.5onchange
> 輸入框的內容改變時發生
> onchange事件支持的標簽input,select,textarea
~~~
<body>
<input type="text" id="txt">
<script>
// input 輸入框有value屬性,可以讀寫
var txt = document.getElementById("txt");
txt.onchange = function(){
this.value = "change"
}
</script>
</body>
~~~

### 1.6onsubmit
> 表單中的確認按鈕被點擊時發生
~~~
<body>
<form id="submit">
<p><input type="text" id="user"></p>
<input type="submit">
</form>
<script>
// 當表單的submit按鈕被點擊的時候,表單會觸發onsubmit事件
var submit = document.getElementById("submit");
var user = document.getElementById("user");
submit.onsubmit = function(){
alert(1);
}
</script>
</body>
~~~

### 1.7onresize
>onresize-->當瀏覽器的窗口大小發生改變的時候觸發
> window.innerWidth-->獲取瀏覽器窗口的width
~~~
<body>
<script>
window.onresize = function(){
alert(window.innerWidth)
}
</script>
</body>
~~~

### 1.8onscroll
> //窗口滾動
~~~
<style>
body{
height: 2000px;
}
</style>
~~~
~~~
<body>
<script>
window.onscroll = function(){
var height = window.scrollY;
console.log(height);
}
</script>
</body>
~~~

* 鍵盤事件與KeyCode屬性
### onkeydown:用戶按下一個鍵盤按鍵時發生
~~~
<body>
<script>
document.onkeydown = function(event){
alert(event.keyCode);
}
</script>
</body>
~~~
效果:當按下某個鍵盤按鈕時出現對應的值
#### 小項目:實現輸入的字數顯示出來
~~~
<body>
<p>你還可以輸入<em id="em" style="color: red">0</em>/300 </p>
<textarea id="txt" cols="30" rows="10"></textarea>
<script>
var em = document.getElementById("em");
var txt = document.getElementById("txt");
txt.onkeydown = function(){
var len = this.value.length;
em.innerHTML = len;
}
</script>
</body>
~~~

- 1.JS的基礎知識
- (1)調試
- (2)變量
- (3)數據類型
- 數據類型之間的轉換
- (4)全局變量和局部變量
- (5)運算符和表達式
- (6)數組
- 2.控制語句DOM,BOM,事件
- (1)控制語句
- (2)DOM的基礎
- 節點
- 改變樣式
- DOM事件
- 3.函數
- (1)聲明函數
- (2)構造函數
- (3)函數的參數
- (4)函數的傳參
- (5)改變this
- (6)重載
- (7)回調函數
- 4.數組
- (1)創建數組
- (2)增刪改查
- (3)字符串與數組的轉換
- 5.正則
- (1)創建正則
- (2)字符串中支持正則
- (3)語法
- 最核心的元字符
- 6.ajax
- (1)原生ajax
- (2)http,get,post
- (3)跨域
- (4)jQuery-ajax
- (5)axios
- 7.面向對象
- (1)原型
- (2)原型鏈,繼承
- (3)多態
- 8.es6小結
- 9.js+canvas實現驗證碼
- 10.js的作用域
- 11.閉包
- 實例
- toggle
- 圖片切換
- swiper
- 遮罩顏色漸變
- 表格添加
- 瀑布流
- ajax數據請求渲染
- 百度地圖