html5鼠标事件HTML onmousedown,up,over,out,move 事件属性

当在段落上按下鼠标按钮时执行一段 JavaScript:




定义和用法
//            onmousedown 属性在鼠标按钮在元素上按下时触发。
//提示:相对于onmousedown 事件的事件次序(限于鼠标左/中键):
//onmousedown onmouseup onclick
//            相对于 onmousedown 事件的事件次序(限于鼠标右键):
//onmousedown onmouseup oncontextmenu

注意:onmousedown 属性不适用以下元素:<base>、<bdo>
          、<br>、<head>、<html>、<iframe>、<meta>、<param>
            、<script>、<style> 或 <title>。


//            鼠标按下 执行ready 函数
            document.onmousedown=ready;
//            鼠标移动执行draw函数

            document.onmousemove=draw;
//            鼠标弹起
            document.onmouseup=endDraw;
//            鼠标移出
            document.onmouseout=endDraw;


//W3实例代码:
<!DOCTYPE html>
<html>
<head>
<script>
function mouseDown()
{
document.getElementById("p1").style.color="red";
}

function mouseUp()
{
document.getElementById("p1").style.color="green";
}
</script>
</head>
<body>

<p id="p1" onmousedown="mouseDown()" onmouseup="mouseUp()">
请点击文本!mouseDown() 函数当鼠标按钮在段落上被按下时触发。此函数把文本颜色设置为红色。mouseUp() 函数在鼠标按钮被释放时触发。mouseUp() 函数把文本的颜色设置为绿色。
</p>

</body>
</html>



posted @ 2016-07-24 17:06  Joe.Smith  阅读(1449)  评论(0编辑  收藏  举报