1. 写插件部分,如下:
var defaults = {
//各种属性,各种参数
}
var options = $.extend(defaults,options);
this.each(function(){
var _this = this;
});
}
})(jQuery);
附上一个例子:
this.each(function(){
//function code
var _this = $(this);
//even row
_this.find('tr:even:not("#thead")').addClass(options.evenRowClass);
//_this.find('#thead').removeClass(options.evenRowClass);
// odd row
_this.find('tr:odd').addClass(options.oddRowClass);
/*_this.find('tr').mou<a href="https://www.jb51.cc/tag/SEO/" title="SEO">SEO</a>ver(function(){
$(this).addClass(options.currentRowClass);
}).mou<a href="https://www.jb51.cc/tag/SEO/" title="SEO">SEO</a>ut(function(){
$(this).removeClass(options.currentRowClass);
});*/
_this.find('tr').bind(options.eventType,function(){
$(this).addClass(options.currentRowClass);
});
_this.find('tr').bind(options.eventType2,function(){
$(this).removeClass(options.currentRowClass);
});
});
return this;
}
})(jQuery);
//arguments,properties
evenRowClass : 'evenRow1', oddRowClass : 'oddRow1', currentRowClass : 'currentRow1'
});
});
附上代码:
<div id="ss">
<input type="text" placeholder="请输入查询数据">
<input id="search" type="button" value="查询">
<table id="table1">
<tr id="thead">
</tr>
<tr>
<td>张三</td>
<td>1</td>
<td>男</td>
<td>20</td>
</tr>
<tr>
<td>李四</td>
<td>2</td>
<td>男</td>
<td>30</td>
</tr>
<tr>
<td>张三</td>
<td>1</td>
<td>女</td>
<td>20</td>
</tr>
<tr>
<td>李四</td>
<td>2</td>
<td>男</td>
<td>30</td>
</tr>
<tr>
<td>王五</td>
<td>3</td>
<td>男</td>
<td>30</td>
</tr>
<tr>
<td>王五</td>
<td>3</td>
<td>男</td>
<td>30</td>
</tr>
<tr>
<td>张三</td>
<td>1</td>
<td>女</td>
<td>20</td>
</tr>
<tr>
<td>李四</td>
<td>2</td>
<td>男</td>
<td>30</td>
</tr>
</table>