实例 触发所选元素的 mousedown 事件

x
 
<!DOCTYPE html>
<html>
<head>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").mousedown(function(){
    $("p").slideToggle();
  });
  $("div").mouseover(function(){
    $("button").mousedown();
  });
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button>Toggle</button><br><br>
<div>Mouse over this text to trigger the mousedown event for the button above.</div>
</body>
</html>
                    

输出结果