English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML reference manual

HTML tag大全

HTML onmousedown event attribute

The onmousedown attribute is used to get or set the event handler function for the mousedown event of the current element

Proprietà degli eventi HTML

Online Example

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

Browser compatibility

IEFirefoxOperaChromeSafari

Tutti i browser mainstream supportano l'attributo evento onmousedown

Definizione e uso

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>.

Differenze tra HTML 4.01 e HTML5

Nessuna.

Sintassi

<elemento onmousedown="script">

Valore dell'attributo

ValoreDescrizione
scriptStabilisce lo script da eseguire quando viene attivato l'evento onmousedown.


Proprietà degli eventi HTML