box.onclick = function(){console.log("单机执行");}
box.ondblclick = function(){console.log("双击执行");}
box.oncontextmenu=function(){console.log("右键单击.自定义右键菜单");}
btn.onmousedown=function(){console.log("鼠标按下");}//移动var i=document.querySelector("#move")i.onmousemove=function(){console.log("鼠标移动");}//抬起btn.onmouseup=function(){console.log("鼠标抬起");}
进入子元素也会移出。
m2.onmouseover=function(){console.log("移入");}m2.onmouseout=function(){console.log("移出");}
m2.onmouseenter=function(){console.log("移入");}m2.onmouseleave=function(){console.log("移出");}
用于( window,document, 输入框 input)
例如< input type="text" id="username">
username.onkeydown = function(){console.log("按下键盘");}
username.onkeyup = function(){console.log("抬起键盘");}
//光标所在 获取焦点box.onfocus = function(){console.log("获取焦点");}//光标移开 失去焦点box.onblur = function(){console.log("失去焦点");}
在失去焦点时对比里面内容不一样才会触发
box.onchange = function(){console.log("change");}
box.oninput=function(){console.log("input");}
在form表单中使用
myform.onsubmit = function(){console.log("submit");return false//阻止事件}myform.onreset = function(){console.log("reset");}
box.ontouchstart = function(){console.log("触摸touchstart");}
box.ontouchmove = function(){console.log("按住移动touchmovr");}
box.ontouchend = function(){console.log("松开touchend");}
box.ontouchcancel = function(){console.log("touchcancel");}