mousedown()方法是jQuery中的内置方法,当在选定元素上按下鼠标左键时,该方法便起作用。
用法:
$(selector).mousedown(function)
参数:该函数接受可选的单参数函数。它用于指定调用mousedown事件时要运行的函数。
返回值:此方法返回具有更改的所选元素。
下面的示例说明了jQuery中的mousedown()方法:
例:
<!DOCTYPE html> 
<html> 
    <head> 
        <title>The mousedown Method</title> 
        <script src= 
        "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> 
        </script> 
          
        <!-- jQuery code to show the working of this method -->
        <script> 
            $(document).ready(function() { 
                $("div").mousedown(function() { 
                    alert("Mouse left key was pressed"); 
                }); 
            }); 
        </script> 
        <style> 
            div { 
                width: 200px; 
                height: 40px; 
                font-weight: bold; 
                border: 2px solid green; 
                padding: 20px; 
            } 
        </style> 
    </head> 
    <body> 
        <!-- click on this button and pop up will appear-->
        <div>Welcome to GeeksforGeeks!</div> 
    </body> 
</html>输出:
在单击段落元素之前:

单击段落元素后:

相关文章:
相关用法
- JQuery first()用法及代码示例
- JQuery val()用法及代码示例
- JQuery last()用法及代码示例
- JQuery eq()用法及代码示例
- JQuery after()用法及代码示例
- JQuery one()用法及代码示例
- JQuery on()用法及代码示例
- JQuery has()用法及代码示例
- JQuery removeAttr()用法及代码示例
- JQuery stop()用法及代码示例
- JQuery mouseout()用法及代码示例
- JQuery queue()用法及代码示例
- JQuery mouseover()用法及代码示例
- JQuery mouseup()用法及代码示例
- JQuery removeClass()用法及代码示例
注:本文由纯净天空筛选整理自kundankumarjha大神的英文原创作品 jQuery | mousedown() with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
