1.需要掌握的知识点

  1)(function($){...}(jQuery)):实际上就是匿名函数并且函数用()阔起来,形成闭包,外界对其内部函数没有影响

    $(function(){…});   jQuery(function($) {…});  $(document).ready(function(){…})用法都是一样的,我们自定义插件时需要用到

  2)$.extend(),$.fn.extend()区别

    最主要的特征:$.extend()是扩展的是Jquery类的静态成员

           $.fn.extend()扩展的是Jquery类实例化对象成员

2.自定义控件分类:带参插件;不带参插件

  1)不带参插件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>不带参数的jquery插件开发</title>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
        (function($){
            $.fn.extend({
                myPlugName:function(){
                    $(this).click(function(){
                        alert($(this).val());    
                    });    
                }
            });    
        })(jQuery);
    </script>
</head>

<body>
    <input type="button" value="点击我" id="btn" />
</body>

    <script type="text/javascript">
          $("#btn").myPlugName();
    </script>
</html
View Code

相关文章:

  • 2021-04-16
  • 2021-04-10
  • 2021-10-02
  • 2021-07-29
猜你喜欢
  • 2021-08-05
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2021-03-30
相关资源
相似解决方案