首页 > Web开发 > 详细

jQuery扩展方法 (插件机制)

时间:2021-05-11 21:52:42      阅读:25      评论:0      收藏:0      [点我收藏+]
  • jQuery.extend(object)
    扩展jQuery对象本身。
    
    用来在jQuery命名空间上增加新函数。 
    
    在jQuery命名空间上增加两个函数:
    
    
    <script>
        jQuery.extend({
          min: function(a, b) { return a < b ? a : b; },
          max: function(a, b) { return a > b ? a : b; }
    });
    
        jQuery.min(2,3); // => 2
        jQuery.max(4,5); // => 5
    </script>
  • jQuery.fn.extend(object)
    扩展 jQuery 元素集来提供新的方法(通常用来制作插件)
    
    增加两个插件方法:
    
    <body>
    
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    
    <script src="jquery.min.js"></script>
    <script>
        jQuery.fn.extend({
          check: function() {
             $(this).attr("checked",true);
          },
          uncheck: function() {
             $(this).attr("checked",false);
          }
        });
    
        $(":checkbox").check()
    </script>
    
    </body>

     

jQuery扩展方法 (插件机制)

原文:https://www.cnblogs.com/zhangyh-blog/p/14756578.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!