jQuery 自定义方法(扩展方法)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.2.1.js"></script>
    <style>
        #div1{
            height: 400px;
            width: 600px
            background-color: #7b7b7b;
            opacity: 1;
        }
    </style>
</head>
<body>
    <div id="div1"></div>
    <script>
        (function ($) {
            $.fn.extend({
                hello:function () {

                     setTimeout("$(\"#div1\").css(\"background-color\",\"red\");",2000);

                     setTimeout("$(\"#div1\").css(\"background-color\",\"black\");",4000);

                     setTimeout("$(\"#div1\").css(\"background-color\",\"gold\");",6000);
                }
            })
        })(jQuery);

        $("#div1").hello()
    </script>
</body>
</html>

 

posted @ 2017-12-22 11:41  归来仍是少年!  阅读(586)  评论(0编辑  收藏  举报