您现在的位置:首页 >> 前端 >> 内容

鼠标与按键事件触发顺序

时间:2017/8/5 14:51:28 点击:

  核心提示:鼠标与按键事件触发顺序。事件触发顺序:之前研究过input文本框的事件触发顺序,今天突然想起来,就做个总结。scriptvar txt = document.querySelector('#txt')...

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

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

</script>

作者:网络 来源:xiaowei的博客