2013-03-13 34 views
0

如何爲複選框添加條件格式。 EX:我有13列4000行,如果一列中至少有一列的數據將複選框添加到第一個單元格。如果一行中的所有單元格都有數據,請檢查該複選框。複選框也應該有ID。有條件地將複選框添加到手機上

我會得到數據,如

[["<input type='checkbox' name='1'","a","a","a","a","a"...], 
["<input type='checkbox' name='2'","a","a","a","a","a"...], 
["<input type='checkbox' name='3'","a","a","a","a","a"...]....]; 

我需要加載,如果用戶做任何刪除或細胞的updations我需要檢查的複選框狀態。 我使用 請幫我...

回答

0

像這樣的負載...

// run through each row in the table 
checkCellsForStuff = $('#myTable tr').each(function() { 
    var cellHasStuff = 0; 

    // check each cell in the current row 
    $('td', this).each(function() { 
     if ($(this).text()) { cellHasStuff = 1 } 
    }); 

    // add a checkbox to the first cell in the current row 
    if (cellHasStuff = 1) { 
     $(this).('td').first().html('<input type="checkbox">'); 
    } 
}); 

然後,點擊...

$('#myTable td').blur(function() { 
    checkCellsForStuff(); 
}); 

這是未經測試,但應讓你開始。

+0

嗨,感謝您的回覆。這是一種方式,但我正在尋找任何渲染類型的格式。因爲以上是給4000行和13列的性能問題。 – user1912935 2013-03-13 13:26:50

+0

然後,它應該可以做到服務器端。 – isherwood 2013-03-13 13:28:36

+0

還有一件事我必須在加載的時候添加複選框。 – user1912935 2013-03-13 13:28:41