onmousedown event

 The onmousedown event occurs when a user presses the mouse button. The button here is not necessarily the left mouse button, but any button on the mouse. It can usually be inserted in various elements of the web page, such as pictures img , DIV blocks, span areas, paragraphs, or even directly written in the <body> tag, used to determine whether users can use the mouse to click on certain specific elements, and then trigger specific JavaScript functions to perform work, all mainstream browsing All devices support the onmousedown event.


onmousedown event syntax

onmousedown = "JavaScript function to be executed"


Onmousedown itself is a mouse event. Use the onmousedown event to monitor web page elements. When a user presses the mouse button on the element, onmousedown will immediately trigger a specific function to perform the work. It should be noted that the mouse button only needs to be clicked. The event will be triggered, and the function will be executed without releasing the button.

Onmousedown event example 1. Insert event in DIV area
<div onmousedown="alert('Hello')" style="padding:5px;background-color:#FFE5B5;">
Please click here to start the test with the mouse
</div>
The above example output
Please use the mouse to click here to start the test
We DIV write blocks in a "onmousedown =" alert ( 'Hello' ) " " means that when users in the DIV anywhere within the block by pressing the mouse button, it will trigger the JavaScript alert statement, the effect is Jump out of the dialog window and display Hello. In the example, padding is the inner margin and background-color is the background color of the DIV block.

onmousedown event example 2: insert event on button button
<input type="button" onmousedown="alert('Hello')" value="test button">
The above example output
The traditional button ( button ) is that when the user presses the button and releases the button, the action will start. If the button is only pressed and not released, there will be no action. If the designer adds onmousedown to the button The event can be made as long as the button is clicked with the mouse, even if the button is not released, the effect of triggering a specific JavaScript function is the same.

Post a Comment

0 Comments