zoukankan      html  css  js  c++  java
  • jQuery插件——自定义jQuery插件

    扩展插件

    1.扩展jQuery的工具方法

      $.extend(object)

    2.扩展jQuery对象的方法

      $.fn.extend(object)

    (function () {
        /**
         * 需求:
         * 1.给$添加4个工具方法
         *  min(a,b) : 返回较小的值
         *  max(c,d) : 返回较大的值
         *  leftTrim() : 去掉字符串左边的空格
         *  rightTrim() : 去掉字符串右边的空格
         *
         *  2.给jQuery对象 添加3个功能方法:
         *  checkAll() : 全选
         *  unCheckAll() : 全不选
         *  reverseCheck() : 全反选
         */
        //扩展$的方法
        $.extend({
            min:function (a,b) {
              return a > b ? b : a
            },
            max:function (a,b) {
                return a < b ? b : a
            },
            leftTrim:function (str) {
                return str.replace(/^s+/,'')
            },
            rightTrim:function (str) {
                return str.replace(/s+$/,'')
            },
        })
        //扩展jQuery对象的方法
        $.fn.extend({
            checkAll:function () {
                this.prop('checked',true)//this是jQuery对象
            },
            unCheckAll:function () {
                this.prop('checked',false)
            },
            reverseCheck:function () {
                //this是jQuery对象
                this.each(function () {
                    //this是dom元素
                    this.checked = !this.checked
                })
            }
            
        })
    })()
    

  • 相关阅读:
    消息队列介绍
    SpringBoot随笔-SpringBoot集成Druid
    Redis-Redis基本类型及使用Java操作
    信息安全
    计算机网络基础
    多媒体技术
    数据库基础
    程序设计基础
    计算机软件体系
    计算机硬件体系
  • 原文地址:https://www.cnblogs.com/yangHS/p/10901890.html
Copyright © 2011-2022 走看看