---
title: "利用Jquery编写自己的框架"
author: "yanyanquan"
date: "2011-09-27T14:41:39Z"
tags: []
categories: ["Web前端"]
slug: "jquery"
draft: false
lastmod: "2011-09-27T14:43:05Z"
id: 1181593
url: "https://kwon.iteye.com/blog/1181593"
---

转载于：[http://www.cnblogs.com/JustinYoung/archive/2010/03/30/jquery-chajian.html](http://www.cnblogs.com/JustinYoung/archive/2010/03/30/jquery-chajian.html)

 

通用的框架

 

```
(function($){
    $.fn.yourName = function(options){
        //各种属性、参数
        }
        var options = $.extend(defaults, options);
        this.each(function(){
        //插件实现代码
        });
    };
})(jQuery);
```

 

Demo：

 

```
/*
 * tableUI 0.1
 * 使用tableUI可以方便地将表格提示使用体验。先提供的功能有奇偶行颜色交替，鼠标移上高亮显示
 */
(function($){
    $.fn.tableUI = function(options){
        var defaults = {
            evenRowClass:"evenRow",
            oddRowClass:"oddRow",
            activeRowClass:"activeRow"            
        }
        var options = $.extend(defaults, options);
        this.each(function(){
            var thisTable=$(this);
            //添加奇偶行颜色
            $(thisTable).find("tr:even").addClass(options.evenRowClass);
            $(thisTable).find("tr:odd").addClass(options.oddRowClass);
            //添加活动行颜色
            $(thisTable).find("tr").bind("mouseover",function(){
                $(this).addClass(options.activeRowClass);
            });
            $(thisTable).find("tr").bind("mouseout",function(){
                $(this).removeClass(options.activeRowClass);
            });
        });
    };
})(jQuery);
```

```
<script type="text/javascript">
	$().ready(function(){
		$(".table_solid").tableUI();
	})
</script>
```