小白教程
所有教程
关于
Search
172.70.178.232
172.70.178.232
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Event mousedown”的源代码
本页内容
上一节:
Event_load
下一节:
Event_mouseenter
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:mousedown()}}[[Category:jquery ref events|37]] = jQuery mousedown() 方法 = [[jquery ref events|jQuery 事件方法]] 在 <div> 元素上按下鼠标左键,插入一些文本: <sample title="" desc="" lang="html" hererun="1"> $("div").mousedown(function(){ $(this).after("Mouse button pressed down."); }); </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("div").mouseup(function(){ $(this).after("<p style='color:green;'>释放鼠标按钮。</p>"); }); $("div").mousedown(function(){ $(this).after("<p style='color:purple;'>按下鼠标按钮。</p>"); }); }); </script> </head> <body> <div>在这个 div 元素中按下和释放鼠标按钮。</div> </body> </html> </run> == 定义和用法 == 当鼠标指针移动到元素上方,并按下鼠标左键时,会发生 mousedown 事件。 mousedown() 方法触发 mousedown 事件,或添加当发生 mousedown 事件时运行的函数。 '''提示:'''该方法通常与 [[event mouseup|mouseup()]] 方法一起使用。 == 语法 == 触发被选元素的 mousedown 事件: $(selector).mousedown() <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").mousedown(function(){ $("p").slideToggle(); }); $("div").mouseover(function(){ $("button").mousedown(); }); }); </script> </head> <body> <p>这是一个段落。</p> <button>切换</button><br><br> <div>鼠标移动到这段文本上触发按钮的 mousedown 事件。</div> </body> </html> </run> 添加函数到 mousedown 事件: $(selector).mousedown(function) <run name=""> <!DOCTYPE html> <html> <head> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("div").mousedown(function(){ $(this).after("<p>Mouse button pressed down.</p>"); }); }); </script> </head> <body> <div style="color:red;">Press down the mouse button over this div element.</div> </body> </html> </run> {| class="table table-striped table-hover" ! 参数 ! 描述 |- | function | 可选。规定 mousedown 事件触发时运行的函数。 |} [[jquery ref events|jQuery 事件方法]]
返回至“
Event mousedown
”。
上一节:
Event_load
下一节:
Event_mouseenter