使用點擊事件寫一個計數器。javascript
onmouseup : 當鼠標按下,鬆開的時候觸發事件。
onmousedown: 當鼠標按下的時候觸發事件。
onMouseOver: 鼠標通過時觸發
onMouseOut: 鼠標移出時觸發
onMouseMove: 鼠標移動時觸發,這個只要在對應的地方移動就會觸發
onclick: 鼠標點擊時觸發,包含按下與鬆開兩個動做。
經過如下實例來觀察onmouseup與onmousedown;up時鼠標按下不會變化,鬆開的時候觸發,而down恰好相反。html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>test</title> </head> <body> <div> <label for="i1">自增計數 </label> <input type="text" value="1" id="i1" > <input type="button" value="開始" class="c1" onmouseup="startcount()"> </div> </body> <script type="text/javascript"> var i = 1; var el1 = document.getElementById("i1"); function startcount() { i ++ ; el1.value = i; } </script> </html>