事件型別
阿新 • • 發佈:2021-01-11
滑鼠
移入box.onmouseenter = function(){ console.log("移入了"); }box.onmouseover = function(){ console.log("移入了"); }
注意:兩者區別在於後者裡面嵌套了一個div有個小盒子的話,會進行事件流,冒泡階段,會在輸出一遍大
div中的程式!!!
移出
box.onmouseleave = function(){ console.log("移出了"); }box.onmouseout = function(){ console.log("移出了"); } 與上文相同。
注意 : mouseover和mouseout 是一對
mouseenter和mouseleave 是一對
滑鼠右擊 - contextmenubox.oncontextmenu = function(){ console.log("右擊"); }滑鼠按下- mousedown
box.onmousedown = function(){ console.log("按下了"); }滑鼠抬起
box.onmouseup = function(){ console.log("抬起了"); }滑鼠移動事件
box.onmousemove = function滾輪事件(){ console.log("移動了滑鼠"); }
window.onmousewheel = function(){ console.log("滾動了滾輪"); }
鍵盤
敲擊鍵盤
window.onkeypress = function(){ console.log("敲擊了鍵盤"); }
表單
input - 只要文字框中的內容發生了改變就會執行的var keywords = document.querySelector("[name='keywords']"); keywords.oninput = function(){ console.log(this.value); this.nextElementSibling.innerText = this.value; }