jquery事件触发

<!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>
posted @ 2020-10-23 09:58  thomas_blog  阅读(169)  评论(0编辑  收藏  举报