事件觸發順序:
之前研究過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
clickkeydown
input(文本框內容改變,輸入或者刪除都會觸發)
keyup
change(文本框失去鼠標焦點,並且內容改變時觸發)注:搜狗輸入法,當輸入漢字,拼音在文本框顯示下劃線狀態,也會觸發keydown,input,keyup事件。