Jquery实现自以为比较好用的表格工具
来源:互联网 发布:mac系统finder快捷键 编辑:程序博客网 时间:2024/05/21 10:26
// author Chase /** * 表格构造方法 * * @use rule : * table must be has <thead> and <tbody> , otherwise not use this method. * * @params : * selected : String type, find table object for jQuery selected. */Table = function(selected) {if(selected){this.setLineNum(selected);this.setOperator(selected);this.setZebraLine(selected);}}/** * 设置表格斑马线 * * @use rule : * table must be has <thead> and <tbody> , otherwise not use this method. * * @params : * selected : String type, find table object for jQuery selected. * style : String type, set table CSS style, optional ,default style is 't-tab-body-two' * * @return : * void */Table.prototype.setZebraLine = function(selected, style) { if(!style){style = "t-tab-body-two";}if(selected){$(selected + " tbody tr:odd").children().addClass(style);}}/** * 设置表格行号 * * @use rule: * table must be has <thead> and <tbody> , otherwise not use this method. * * @params: * selected : String type, find table object for jQuery selected. * * @return : * void */Table.prototype.setLineNum = function(selected){if(selected){$(selected + " thead tr").prepend("<td class='t-tab-head'><b>序号</b></td>");$(selected + " tbody tr").each(function(index){$(this).prepend("<th class='t-tab-body'>" + eval(index+1) +"</th>");});}}/** * 设置表格操作选项 * * @use rule: * table must be has <thead> and <tbody> , otherwise not use this method. * * @params: * selected : String type, find table object for jQuery selected. *templeat : String type, the operator is defalut edit and remove: * * @return : * void */Table.prototype.setOperator =function(selected,templeat) {if(!templeat){templeat = "<a href='javascript:void(0)' onclick='update(this)'>编辑</a> " + "<a href='javascript:void(0)' onclick='remove(this)'>删除</a> ";}if(selected){$(selected + " thead tr").append("<td class='t-tab-head'><b>操作</b></td>");$(selected + " tbody tr").each(function(index){$(this).append("<th class='t-tab-body'>" + templeat +"</th>");});}}调用:<script language="javascript">$(function () {/*var tab = new Table();tab.setLineNum("#dataTable"); */var tab = new Table("#dataTable");});</script>