PHP速学视频免费教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
鼠标事件是鼠标按钮被按下(左键或者右键)时触发。不能通过键盘触发。鼠标事件触发的顺序是怎样的?以下给出了详细的例子,
dom3级事件中定义了9个鼠标事件。
mousedown:鼠标按钮被按下(左键或者右键)时触发。不能通过键盘触发。
mouseup:鼠标按钮被释放弹起时触发。不能通过键盘触发。
click:单击鼠标左键或者按下回车键时触发。这点对确保易访问性很重要,意味着onclick事件处理程序既可以通过键盘也可以通过鼠标执行。
dblclick:双击鼠标左键时触发。
mouseover:鼠标移入目标元素上方。鼠标移到其后代元素上时会触发。
mouseout:鼠标移出目标元素上方。
mouseenter:鼠标移入元素范围内触发,该事件不冒泡,即鼠标移到其后代元素上时不会触发。
mouseleave:鼠标移出元素范围时触发,该事件不冒泡,即鼠标移到其后代元素时不会触发。
mousemove:鼠标在元素内部移到时不断触发。不能通过键盘触发。
note:
在一个元素上相继触发mousedown和mouseup事件,才会触发click事件。两次click事件相继触发才会触发dblclick事件。
如果取消 了mousedown或mouseup中的一个,click事件就不会被触发。直接或间接取消了click事件,dblclick事件就不会被触发了。
举例:通过双击按钮,看一下上面触发的事件。
<input><script> var btn = document.getElementById("btn"); btn.addEventListener("mousedown",function(event){ console.log("mousedown"); },false); btn.addEventListener("mouseup",function(){ console.log("mouseup"); },false); btn.addEventListener("click", function () { console.log("click"); },false); btn.addEventListener("dblclick", function () { console.log("dblclick"); },false);</script>
View Code
区别:
mouseover事件会冒泡,这意味着,鼠标移到其后代元素上时会触发。
mouseenter事件不冒泡,这意味着,鼠标移到其后代元素上时不会触发。
举例:
nbsp;html> <meta> <title></title> <style> #outer{ position: absolute; width: 200px; height: 200px; top:0; left: 0; bottom:0; right: 0; margin: auto; background-color: pink; } #inner{ position: absolute; width: 100px; height:100px; top:50%; left:50%; margin-left: -50px; margin-top: -50px;; background-color: orange; text-align: center; line-height: 100px; } #outer,#inner{ border-radius:50%; } </style> <script></script> <p> </p><p> </p> <script> var parentp = document.getElementById("outer"); parentp.addEventListener("mouseover", function () { console.log("父p的mouseover事件被触发"); },false); //parentp.addEventListener("mouseenter", function () { // console.log("父p的mouseenter事件被触发"); //},false); //parentp.addEventListener("mouseout", function () { // console.log("父p的mouseout事件被触发"); //},false); //parentp.addEventListener("mouseleave", function () { // console.log("父p的mouseleave事件被触发"); //},false);</script>
View Code
note:
mouseover对应mouseout,mouseenter对应mouseleave。效果可以取消上面代码的注释来看。
jquery中hover API是把mouseenter 和mouseleave组合在一起来用的。
<script>document.onmousedown=function (ev){ var oEvent = ev||event; //IE浏览器直接使用event或者window.event得到事件本身。 alert(oEvent.button);// IE下鼠标的 左键是1 , 右键是2 ff和chrome下 鼠标左键是0 右键是2};</script>
相关推荐:
已抢7204个
抢已抢94834个
抢已抢14826个
抢已抢52064个
抢已抢194754个
抢已抢87263个
抢