jquery事件触发

  • A+
所属分类:Web前端
<!DOCTYPE html> <html>     <head>         <meta charset="utf-8" />         <meta name="viewport" content="width=device-width, initial-scale=1">         <title></title>         <script src="jquery-3.5.1.min.js" type="text/javascript" charset="utf-8"></script>          <style type="text/css">             #box {                 background-color: red;                 width: 100px;                 height: 100px;             }         </style>          <script type="text/javascript">             $(document).ready(function() {                 $(document).click(function() {                     alert("click")                 });                  // 触发浏览器行为                 $(document).click();                 // 触发浏览器行为                 $(document).trigger("click");                 // 不触发浏览器行为                 $(document).triggerHandler("click");                  // 不触发浏览器行为 获得焦点举例                 $(document).triggerHandler("focus");             });         </script>     </head>     <body>         <div id="box">         </div>     </body> </html>