不難遍歷每個第一單元行以確定單元格內容是否與下一行中第一個單元格的內容「相等」,因此您可以輕鬆地創建一個函數來返回匹配行的數組,例如
// Return an array of arrays of row indexes
// whose first cell content is equal
function getMatchingRows(table) {
var rows = table.rows;
var allMatches = [];
var currentMatches, currentValue, previousValue;
for (var i=0, iLen=rows.length; i<iLen; i++) {
currentValue = getText(rows[i].cells[0]);
if (currentValue == previousValue) {
if (!currentMatches) {
currentMatches = [i-1, i];
} else {
currentMatches.push(i);
}
} else {
previousValue = currentValue;
if (currentMatches) {
allMatches.push(currentMatches);
currentMatches = null;
}
}
}
return allMatches;
}
// Simple function to return element's text content
function getText(el) {
if (typeof el.textContent == 'string') {
return el.textContent;
} else if (typeof el.innerText == 'string') {
return el.innerText;
}
}
現在它只是一個應用適當的風格與細胞的事,所以你需要一個hightlighRows功能hightlights基於行索引數組行和hightlightColumnSegment,突出細胞基礎上,相同的行索引數組和單元索引(或者如果要突出顯示相鄰列和行的塊,可能還有多個單元索引)。
getText函數是非常簡單的,但足以舉例。
你能否澄清一下「如果Row11等於Row21,那麼這兩行之間應該有一個邊框」? 您的列已命名,但您沒有「行」,您標記的是元素。你想圍繞匹配元素的邊框還是圍繞包含匹配元素的行? – Sinetheta
我需要知道幾件事情來幫助。你如何在Web服務中呈現數據?您是使用JSP在DOM中佈局表格還是使用jQuery通過JSON AJAX服務傳遞它?你有沒有想過你將如何確定比賽?例如,服務器端可以將它作爲查詢的一部分,還是在演示文稿中,或者您希望在客戶端的javascript中執行此操作?如果您不確定,請告訴我們更多關於您目前爲止所擁有的信息,或者您是否正在尋找方法。 – mbarnes