English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The onmousedown attribute is used to get or set the event handler function for the mousedown event of the current element
Execute JavaScript on the paragraph when the mouse button is pressed:
<!DOCTYPE html> <html> <head> <title>Using the HTML onmousedown event attribute (Basic Tutorial Website oldtoolbag.com)</title> </head> <body> <p id="p1" onmousedown="mouseDown()" onmouseup="mouseUp()"> Click on the text! When the mouse button is pressed on this paragraph, the mouseDown() function will be triggered. This function sets the text color to red. When the mouse button is released, the mouseUp() function will be triggered. The mouseUp() function sets the text color to green.</p> <script> function mouseDown() { document.getElementById("p1").style.color = "red"; } function mouseUp() { document.getElementById("p1").style.color = "green"; } </script> </body> </html>Test to see «/»
The mousedown event is triggered at the moment the mouse button is pressed on the current element
IEFirefoxOperaChromeSafari
Tutti i browser mainstream supportano l'attributo evento onmousedown
L'attributo onmousedown viene attivato quando si preme un pulsante del mouse su un elemento.
Suggerimento: Ordine di attivazione degli eventi correlati a onmousedown (bottone sinistro/centrale del mouse):
onmousedown
onmouseup
Ordine di attivazione degli eventi correlati a onclick e onmousedown (bottone destro del mouse):
onmousedown
onmouseup
oncontextmenu
Attenzione: L'attributo onmousedown non può essere utilizzato per i seguenti elementi: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, o <title>.
Nessuna.
<elemento onmousedown="script">
Valore | Descrizione |
---|---|
script | Stabilisce lo script da eseguire quando viene attivato l'evento onmousedown. |