JQ插件写法二

来源:互联网 发布:阿里云计算技术架构 编辑:程序博客网 时间:2024/05/02 04:18

参数放在外面的写法:

<!DOCTYPEhtml>

<html>

    <head>

      <metacharset="utf-8">

      <title></title>

    </head>

    <scripttype="text/javascript"src="js/jquery-1.7.1.js"></script>

    <body>

      <pstyle="color:burlywood;">今天天气真好!!!</p>

      <scripttype="text/javascript">

          (function($){

             vardefaults={

                 color:'red'

             };

             $.fn.extend({

                 testCC:function(options){

                    varopts=$.extend(defaults,options);

                    returnthis.each(function(){

                        varobj=$(this);

                        obj.click(function(){

                           obj.css({

                               color:defaults.color

                           });

                           console.log(opts.color);

                        });

                    });

                 }

             });

          })(jQuery);

          //test

          $(function(){

             $('p').testCC({color:'green'});

          });

       </script>

    </body>

</html>

0 0
原创粉丝点击