Jquery实现自以为比较好用的表格工具

// 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)' οnclick='update(this)'>编辑</a> " +
				   "<a href='javascript:void(0)' οnclick='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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值