js堅持不懈之17:onmousedown、onmouseup 以及 onclick 事件

踏破凌霄城發表於2019-02-19
<!DOCTYPE html>
<html>
<body>
<div onmouseover = "mOver(this)" onmouseout = "mOut(this)" style = "background-color:green;width:120px;height:20px;padding:40px;color:#ffffff;">把滑鼠移到上面</div>

<script>
function mOver(obj)
{
    obj.innerHTML = "謝謝"
}

function mOut(obj)
{
    obj.innerHTML = "把滑鼠移到上面"
}
</script>
</body>

</html>

2.

<!DOCTYPE html>
<html>
<body>

<div onmousedown = "mDown(this)" onmouseup = "mUp(this)" style = "background:green;color:#ffffff;width:90px;height:20px;padding:40px;font-size:12px;">請點選這裡</div>

<script>
function mDown(obj)
{
    obj.style.backgroundColor = "#1ec5e5";
    obj.innerHTML = "請釋放滑鼠按鈕"
}

function mUp(obj)
{
    obj.style.backgroundColor = "green";
    obj.innerHTML = "請按下滑鼠按鈕"
}
</script>

</body>
</html>

 

相關文章