jquery插件开发
(function($){
$.fn.yourName = function(options){
//各种属性、参数
var defaults = {
foreground: 'red',
background: 'yellow'
};
}
var options = $.extend(defaults, options);
this.each(function(){
//插件实现代码
});
};
})(jQuery);
http://www.jb51.net/article/22849.htm
完整:
(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" language="javascript" src="js/jquery.tableui.js"></script> | |
<script type="text/javascript"> | |
$().ready(function(){ | |
$(".table_solid").tableUI(); | |
}) | |
</script> |