鼠标与按键 事件触发顺序

xiaoxiao2021-02-28  94

事件触发顺序: 之前研究过input文本框的事件触发顺序,今天突然想起来,就做个总结。

<input type="text" name="" id="txt"> <script> var txt = document.querySelector('#txt'); txt.onmousedown = function(){ console.log('onmousedown'); } txt.onmouseup = function(){ console.log('onmouseup'); } txt.onfocus = function(){ console.log('onfocus'); } txt.onclick = function(){ console.log('onclick'); } txt.onkeydown = function(){ console.log('onkeydown'); } txt.onkeyup = function(){ console.log('onkeyup'); } txt.onchange = function(){ //文本框失去鼠标焦点,并且内容改变时触发 console.log('onchange'); } txt.oninput = function(){ console.log('oninput'); }

事件触发顺序: mousedown focus mouseup click

keydown input(文本框内容改变,输入或者删除都会触发) keyup change(文本框失去鼠标焦点,并且内容改变时触发)

注:搜狗输入法,当输入汉字,拼音在文本框显示下划线状态,也会触发keydown,input,keyup事件。

转载请注明原文地址: https://www.6miu.com/read-19395.html

最新回复(0)