• jQuery插件制作



    模板:
    (function($){
    $.fn.plugins=function(options){


    var defaults = {

    }
    var options = $.extend(defaults,options);
    this.each(function(){

    })
    }
    return this;
    })(jQuery);


    例子:做一个tab标签切换插件
    <div class="tab">
    <ul class="tabnav">
    <li class="current">html</li>
    <li>css</li>
    <li>js</li>
    </ul>
    <div class="tabcontent">
    <div style="display: block">html</div>
    <div>css</div>
    <div>js</div>
    </div>
    </div>
    <style>
    *{padding: 0;margin: 0}
    .tabnav li{float: left; 150px;height: 26px;line-height: 26px;text-align: center;margin-right: 3px;border: 1px solid blue;border-bottom: none;list-style: none;cursor: pointer}
    .tabcontent{clear:both}
    .tabcontent div{border: 1px solid blue;display: none; 500px;height:200px }
    .tabnav li.current{background: blue;color: white;font-weight: bold}
    <script>
    $.fn.tab=function(options){


    var defaults = {
    currentClass:"current",
    eventType:"click",
    tabNav:".tabnav>li",
    tabContent:".tabcontent>div"
    }
    var options = $.extend(defaults,options);
    this.each(function(){
    var _this = $(this);
    _this.find(options.tabNav).bind(options.eventType,function(){
    $(this).addClass(options.currentClass).siblings().removeClass(options.currentClass)
    var index = $(this).index();
    _this.find(options.tabContent).eq(index).show().siblings().hide()
    })
    })
    return this;
    }

    })(jQuery);
  • 相关阅读:
    Nginx原理入门教程
    MSDN原版系统镜像ISO下载站
    JWT跨域身份验证解决方案
    PHP获取毫秒时间戳
    IDCode校验算法
    PurpleAir空气质量数据采集
    检测微信好友是否删除自己
    京东联盟开发(13)——获取官方活动推广数据
    微信二维码标准
    车牌号正则表达式
  • 原文地址:https://www.cnblogs.com/bhan/p/5401970.html
Copyright © 2020-2023  润新知