zoukankan      html  css  js  c++  java
  • JavaScript生成表格

    (function(window){
    	var grid = {
    			/*
    			 * 产生表格主体
    			 */
    			gridbody : function(thead, theadname, colswidth, infopage, startIndex, tbody) {
    			var numcol = thead.length,
    				numrow = tbody.length,
    				gridstr = '<div id="grid"><table class="dataTable" style="100%;"><tbody><tr class="odd_row">', 
    				i,
    				j; 
    			//产生表头
    			//alert(gridstr);
    			gridstr += '<td style="' + colswidth[0]
    					+ ';">' + theadname[0] + '</td>';
    			for (i = 1; i < numcol; i++) {
    				gridstr += '<td style="' + colswidth[i] + ';">'
    						+ theadname[i] + '</td>';
    			}
    			//产生每一行
    			for (i = 0; i < numrow; i++) {
    				var odd_even;
    				if(i%2){
    					odd_even = ' class="even_row" ';
    				}else{
    					odd_even = ' class="even_row2" ';
    				}
    				gridstr += '<tr '
    						+ odd_even
    						+'><td>'
    						+ (startIndex + i)
    						+ '</td>';
    				for (j = 1; j < numcol; j++) {
    					if (j == infopage.hrefcol) {
    						gridstr += '<td><a href="' + infopage.infohref + '?'
    								+ infopage.argument + '='
    								+ tbody[i][infopage.argument] + '">'
    								+ tbody[i][thead[j]] + '</a></td>';
    					} else {
    						gridstr += '<td>' + tbody[i][thead[j]] + '</td>';
    					}
    				}
    				gridstr += '</tr>';
    			}
    			
    			gridstr += '</tbody></table></div>';
    			
    			return gridstr;
    		},
    		/*
    		 * 产生表格分页栏, 可传递点击分页时触发的函数名,参数仍是当前页的id
    		 * para = {pagecount : 3, curpage : 1, clickAction : "myfunction"}
    		 */
    		gridfoot : function(para){
    			var i;
    		    var pageBarStr = '<div>';
    		    if(para.pagecount < 8){
    		        for(i = 1; i <= para.pagecount; i++){
    		        	if(i == para.curpage){
    		        		pageBarStr += '<strong>' + i + '</strong>';
    		        	}else{
    		        		pageBarStr += '<a href="javascript:;" onclick="'
    		        			+ para.clickAction
    		        			+'(this.innerHTML)">'
    				            + i
    				            +'</a>';
    		        	}
    		        }
    		    }else if(para.pagecount == 8){
    		        if(para.curpage < 5){
    		            for(i = 1; i < 7; i++){
    		            	if(i == para.curpage){
    			        		pageBarStr += '<strong>' + i + '</strong>';
    		            	}else{
    		            		pageBarStr += '<a href="javascript:;" onclick="'
    		            			+ para.clickAction
    		            			+'(this.innerHTML)">'
    			                    + i
    			                    +'</a>';
    		            	}
    		            }
    		            pageBarStr += '...<a href="javascript:;" onclick="'
    		            	+ para.clickAction
    		            	+'(this.innerHTML)">8</a>';
    		        }else{
    		            pageBarStr += '<a href="javascript:;" onclick="'
    		            	+ para.clickAction
    		            	+'(this.innerHTML)">1</a>...';
    		            for(i = 3; i <= 8; i++){
    		            	if(i == para.curpage){
    			        		pageBarStr += '<strong>' + i + '</strong>';
    			        	}else{
    			                pageBarStr += '<a href="javascript:;" onclick="'
    			                	+ para.clickAction
    			                	+'(this.innerHTML)">'
    			                    + i
    			                    +'</a>';
    			        	}
    		            }
    		        }
    		    }else{ //pagecount > 8
    		        if(para.curpage < 5){
    		            for(i = 1; i < 7; i++){
    		            	if(i == para.curpage){
    			        		pageBarStr += '<strong>' + i + '</strong>';
    			        	}else{
    			                pageBarStr += '<a href="javascript:;" onclick="'
    			                	+ para.clickAction
    			                	+'(this.innerHTML)">'
    			                    + i
    			                    +'</a>';
    			        	}
    		            }
    		            pageBarStr += '...<a href="javascript:;" onclick="'
    		            	+ para.clickAction
    		            	+'(this.innerHTML)">'
    		                + para.pagecount
    		                +'</a>';
    		        }else if(para.curpage > para.pagecount - 4){
    		            pageBarStr += '<a href="javascript:;" onclick="'
    		            	+ para.clickAction
    		            	+'(this.innerHTML)">1</a>...';
    		            for(i = para.pagecount - 5; i <= para.pagecount; i++){
    		            	if(i == para.curpage){
    			        		pageBarStr += '<strong>' + i + '</strong>';
    			        	}else{
    			                pageBarStr += '<a href="javascript:;" onclick="'
    			                	+ para.clickAction
    			                	+'(this.innerHTML)">'
    				                + i
    				                +'</a>';
    			        	}
    		            }
    		        }else{
    		            pageBarStr += '<a href="javascript:;" onclick="'
    		            	+ para.clickAction
    		            	+'(this.innerHTML)">1</a>...';
    		            for(i = para.curpage - 2; i < para.curpage + 3; i++){
    		            	if(i == para.curpage){
    			        		pageBarStr += '<strong>' + i + '</strong>';
    			        	}else{
    			                pageBarStr += '<a href="javascript:;" onclick="'
    			                	+ para.clickAction
    			                	+'(this.innerHTML)">'
    				                + i
    				                +'</a>';
    			        	}
    		            }
    		            pageBarStr += '...<a href="javascript:;" onclick="'
    		            	+ para.clickAction
    		            	+'(this.innerHTML)">'
    			            + para.pagecount
    			            +'</a>';
    		        }
    		    }
    		    pageBarStr += '</div>';
    		    return pageBarStr;
    		}
    	};
    	window.grid = grid;
    })(window);
    

      

  • 相关阅读:
    Call指令和Ret指令讲解02 零基础入门学习汇编语言49
    指针01 零基础入门学习C语言41
    Call指令和Ret指令讲解03 零基础入门学习汇编语言50
    Call指令和Ret指令讲解01 零基础入门学习汇编语言48
    指针01 零基础入门学习C语言41
    指针02 零基础入门学习C语言42
    Call指令和Ret指令讲解02 零基础入门学习汇编语言49
    VC++2012编程演练数据结构《31》狄杰斯特拉算法
    VC++2012编程演练数据结构《30》弗洛伊德算法
    在Windows Azure Web Site上为Node.js自动安装NPM包
  • 原文地址:https://www.cnblogs.com/realwall/p/2192260.html
Copyright © 2011-2022 走看看