? 獲取按鈕
? ? ? ? let btn = document.querySelector('#btn')
? 獲取文本框
? ? ? ? let txt = document.querySelector('#txt')
? ?搜索按鈕注冊點擊事件
? ? ? ? btn.onclick = function(){
? ? ? ? ? ? alert('正在搜索!'+txt.value)
? ? ? ? }
? ? ? ? 鍵盤按下事件
? ? ? ? txt.onkeydown = function() {
? ? ? ? ? ? console.log('鍵盤按下');
? ? ? ? ? ? }
? ? ? ? 鍵盤產(chǎn)生輸出字符事件
? ? ? ? txt.onkeypress = function() {
? ? ? ? ? ? console.log('產(chǎn)生輸出字符');
? ? ? ? }
? ? ? ? 鍵盤彈起事件
? ? ? ? txt.onkeyup = function(e){
? ? ? ? ? ? console.log('鍵盤彈起');
? ? ? ? ? ? 獲取鍵盤編碼
? ? ? ? ? ? let {keyCode} = e
? ? ? ? ? ? 判斷是否是回車鍵
? ? ? ? ? ? if(keyCode===13){
? ? ? ? ? ? ? ? 觸發(fā)按鈕的點擊事件
? ? ? ? ? ? ? ? btn.click()
? ? ? ? }
? ? ? ? }