插件开发(对象级)


html部分
<table class="table">
    <tr>
        <th>姓名</th>
        <th>年龄</th>
        <th>性别</th>
        <th>身高</th>
    </tr>
    <tr>
        <td>张三</td>
        <td>26</td>
        <td>男</td>
        <td>176</td>
    </tr>
    <tr>
        <td>李四</td>
        <td>20</td>
        <td>男</td>
        <td>185</td>
    </tr>
</table>
<script>
$(function(){
$(".table").tab({
evenClass:"even1",
oddClass:"odd1",
currentClass:"current1",
eventType:"mouseover"
});

})
</script>



js部分
;(function($){
    $.fn.tab=function(options){
        var defaults = {
            //各种参数,各种属性
            evenClass:"even",
            oddClass:"odd",
            currentClass:"current",
            eventType:"mouseover",
            eventType2:"mouseout"
        };
        var _this =  $(this);
        var options = $.extend(defaults,options);

        this.each(function(){//this
            ...............
        });
    }
})(jQuery);

 

posted @ 2019-05-15 09:34  迷失地  阅读(152)  评论(0编辑  收藏  举报