<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事件。