js鼠标事件

2018-08-29 10:51:47 浏览数 (1)

页面加载事件(onload),鼠标双击事件(ondbclick)

代码语言:javascript复制
window.onload=function(){
                //绑定元素,执行对应事件 鼠标双击(ondblclick)
                //鼠标双击事件ondblclick
                document.getElementById('d2').ondblclick=function(){
                    alert('我是双击显示的');
                }
            }

鼠标摁下(onmousedown)事件(摁下就执行,鼠标无需抬起)

代码语言:javascript复制
            window.onload=function(){
                //绑定元素,执行鼠标按下操作  鼠标摁下(onmousedown)
                document.getElementById('d3').onmousedown=function(){
                    alert('我是鼠标摁下提示');
                }
            }

鼠标抬起(onmouseup)事件(摁下后,鼠标回弹才执行)

代码语言:javascript复制
            window.onload=function(){
                //绑定元素,执行鼠标抬起事件   鼠标抬起(onmouseup)
                document.getElementById('d4').onmouseup=function(){
                    alert('鼠标抬起的提示');
                }
            }

鼠标移动(onmousemove)事件

代码语言:javascript复制
            window.onload=function(){
                //绑定元素,执行鼠标移动事件   鼠标移动(onmousemove)
                document.getElementById('d5').onmousemove=function(){
                    alert('鼠标移动的提示');
                }
            }

鼠标移入(onmouseover)事件

代码语言:javascript复制
            window.onload=function(){
                //绑定元素,执行鼠标移入事件   鼠标移入(onmousemove)
                document.getElementById('d6').onmouseover=function(){
                    alert('鼠标移入操作');
                }
            }

鼠标移出(onmouseout)事件    

代码语言:javascript复制
            window.onload=function(){
                //绑定元素,执行鼠标移出事件   鼠标移出(onmouseout)
                document.getElementById('d7').onmouseout=function(){
                    alert('鼠标移出操作');
                }
            }

PS:鼠标移动(onmousemove)和鼠标移入(onmouseover)区别:移动事件指鼠标只要移动就产生事件,移入事件需要移入到指定的对象内才执行事件

seo

0 人点赞