Home  >  Article  >  Web Front-end  >  jQuery: usage and definition of mousedown event

jQuery: usage and definition of mousedown event

黄舟
黄舟Original
2017-06-28 09:12:181546browse

Overview

Bind a handler function to the mousedown event of each matching element.

The mousedown event will be triggered after the mouse clicks on the element

Parameters

fnFunctionV1.0

Bind in the mousedown event of each matching element processing function.

[data],fnString,FunctionV1.4.3

data:mousedown([Data], fn) data can be passed in for function fn to process.

fn: The handler function bound in the mousedown event of each matching element.

Example

Description:

Hide or show an element when the mouse button is pressed:

jQuery Code:

$("button").mousedown(function(){ $("p").slideToggle(); });

Example 1

Hide or show elements when the mouse button is pressed:

##

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").mousedown(function(){
    $("p").slideToggle();
  });
});
</script>
</head>
<body>
<p>这是一个段落。</p>
<button>切换</button>
</body>
</html>

Example 2

Move the mouse on this paragraph to activate the mousedown event of the button


<span style="font-weight: normal;"><span style="font-weight: normal;"><html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").mousedown(function(){
    $("p").slideToggle();
  });
  $("#mousePara").mouseover(function(){
    $("button").mousedown();
  });
});
</script>
</head>
<body>
<p>
<p>这是一个段落。</p>
<p>这是另一个段落。</p>
</p>
<button>切换</button>
<p id="mousePara">如果您把鼠标移动本段落上,会激活上面这个按钮的 mousedown 事件。</p>
</body>
</html></span><span style="font-weight: 400;">
</span></span>




Definition and usage

When the mouse pointer moves over the element, And when the mouse button is pressed, the mousedown event occurs.

Unlike the click event, the mousedown event only requires the key to be pressed and does not need to be released to occur.

The mousedown() method triggers the mousedown event, or specifies the

function to be run when the mousedown event occurs.

Syntax
$(selector).mousedown(function)

##Parametersfunction
Description
Optional. Specifies a function to run when a mousedown event occurs.

The above is the detailed content of jQuery: usage and definition of mousedown event. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn