设置表格列的长度等于

时间:2015-05-20 17:28:16

标签: javascript jquery css

如果我需要这样做,css会怎么样?我有一个获取数据和输出行的javascript函数。数据匹配(如第1行的第一个元素与第2行的第一个元素相同,第二个与第二个相同等) 但有时上排的一个元素会比相应的元素长得多,所以它不会像直柱一样下降。我该如何解决这个问题?

        rowIndex=0;
        while(rowIndex<table.length){
            present_row = $("#table").append("<div class='row'></div>");

            itemIndex= 0;                
            while(itemIndex<table[rowIndex].length){
                present_row.append("<div class='tableItem'>"+ table[rowIndex][itemIndex] +"</div>");
                itemIndex+=1;
            }
            rowIndex+=1
        }
    }

这给了我一组不是

的行

2 个答案:

答案 0 :(得分:3)

使用真实表:

from tkinter import *

class Application(object):
    def __init__(self, parent):
        self.x = list(range(1000))
        self.labels = []
        self.parent = parent
        self.navigation_frame = Frame(self.parent)
        self.canvas =  Canvas(self.parent, bg='black', width = 200, height = 500)
        self.mainFrame = Frame(self.canvas)
        self.navigation_frame.pack()
        for i in range(100):
            self.labels.append(Label(self.mainFrame, text=str(i)))
            self.labels[i].grid()
        self.back_button = Button(self.navigation_frame, text='Back', command=lambda: self.move(-2))
        self.quick_nav = Entry(self.navigation_frame, width=3)
        self.quick_nav.bind('<Return>', lambda x: self.move(self.quick_nav.get()))
        self.forward_button = Button(self.navigation_frame, text='Forward', command=lambda: self.move(0))

        temp = divmod(len(self.x), len(self.labels))
        self.pages = temp[0] + (1 if temp[1] else 0)

        self.you_are_here = Label(self.navigation_frame, text='Page 1 of ' + str(self.pages))
        self.current_page = 1
        self.back_button.grid(row=0, column=0)
        self.quick_nav.grid(row=0, column=1)
        self.forward_button.grid(row=0, column=2)
        self.you_are_here.grid(row=0, column=3)
        self.scroll = Scrollbar(self.parent, orient = VERTICAL, command=self.canvas.yview)
        self.canvas.configure(yscrollcommand=self.scroll.set)
        self.scroll.pack(side='right', fill='y')
        self.canvas.pack(side='left', fill='both')
        self.canvas.create_window((4,4), window=self.mainFrame, anchor="nw", tags="frame")

        self.canvas.configure(yscrollcommand = self.scroll.set)
        self.mainFrame.bind("<Configure>", self.update)   

    def update(self, event):
        self.canvas.configure(scrollregion=self.canvas.bbox("all"))

    def move(self, direction):
        if (self.current_page == 1 and direction == -2) or (self.current_page == self.pages and direction == 0):
            return
        if direction in (-2, 0):
            self.current_page += direction + 1
        else:
            try:
                temp = int(direction)
                if temp not in range(1, self.pages+1):
                    return
            except ValueError:
                return
            else:
                self.current_page = temp
        for i in range(len(self.labels)):
            try:
                location = str(self.x[len(self.labels)*(self.current_page - 1) + i])
            except IndexError:
                location = ''
            self.labels[i].config(text=location)
        self.you_are_here.config(text='Page ' + str(self.current_page) + ' of ' + str(self.pages))

if __name__ == '__main__':
    root = Tk()
    app = Application(root)
    root.mainloop()

答案 1 :(得分:0)

您可以使用以下方法使行的高度相等

  

$(document).ready(function(){       var nHeight = 0;       $(&#39; .tableItem&#39;)。each(function(){           var defHeight = $(this).height();           nHeight = defHeight&lt; nHeight? nHeight:defHeight;       });       $(&#39; .tableItem&#39)的高度(nHeight参数)。 });   });