사용자가 행과 열을 병합 할 수있을 때 테이블을 만들려고합니다. 정상적으로 작동하는 열에 대한 코드가 있고 행도 거의 있습니다. 그러나 행 범위를 3에서 2로 변경하면 추가 열이 추가됩니다.
이 바이올린 에서 내가 의미하는 바를 알 수 있습니다 .
그리고 여기에 내 코드가 있습니다.
function growRow(td, span, cell_content) {
var cell_content = (typeof cell_content === 'undefined') ? '<td></td>' : cell_content
var row = td.closest("tr")
var index = td.index()
var old_span = (typeof td.attr('rowspan') === 'undefined') ? 1 : Number(td.attr('rowspan'))
var table = row.parents('table')
var content
td.attr('rowspan', span)
if (span > old_span) {
// If we want to merge cells, this is easy
var selector = "tr:lt(" + (span - 1) + ")"
row.nextAll(selector).each(function () {
// Grab the content from each cell
content = $("td:eq(" + index + ")", $(this)).html()
$("td:eq(" + index + ")", $(this)).remove()
})
// Get the next cell down
row = $('tr:eq('+ span +')')
// Append the content to make it look as though the cells are 'moving down'
row.find('td:eq('+ index +')').html(content)
} else {
// This is where I'm having problems
// Get the number of cells we need to put back
count = old_span - span
// Work through the rows
for (var i=0; i < count ; i++) {
// Get the row at the right index
r = $(row.nextAll()[i])
if (index == 0) {
// If we're at the beginning of a row, we need to prepend
r.prepend(cell_content)
} else {
// Otherwise use nth-child to append in the right place
r.find('td:nth-child(' + index + ')').after(cell_content)
}
}
}
return td
}
내가 DAYS 동안 이것을 해왔 기 때문에 어떤 도움이라도 대단히 감사하겠습니다!
r + count
오프셋 에서 행을 가져와야합니까? 그냥 r
?
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다