第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在指定的 <tr> 之后添加行

在指定的 <tr> 之后添加行

楊魅力 2023-11-02 17:09:41
基本上我有一個表,用戶可以添加行。根據(jù)行類型,它們的添加方式略有不同。標準行始終由 .append() 添加,但“指令”行應(yīng)始終添加在創(chuàng)建或修改的最后一行之后。//Lastrow is always a Jquery object of a table row that's present on the DOM.//The variable is set/reset whenever a row is created or modified.lastRow = $(row)... //indexRow = lastRow, but passed as an argument. function addRow(rowType, indexRow){  newRow="<tr><td>Test</td></tr>";    //Want to add the new row after the last created row, and it doesn't work.  //However if lastRow is an existing row that's been modified, it does work.  if(rowType =='instructionRow'){      indexRow.after($(newRow));      indexRow.get(0).scrollIntoView();  }  if(rowType=="normalRow"){     $('tableId').append(newRow);     lastRow = $(newRow);  }}LastRow 設(shè)置位置的一些示例//In the add row function itself, if the row is not an instruction row.//Where newRow = HTML for a table row//This does not work when you try addRow("instructionRow", lastAddedRow) after it  if(rowType=="normalRow"){     lastRow = $(newRow);  }//In a row that is updated.//Where row is a row in the dom, in a .each() loop//In this case, the addRow("instructionRow", lastRow) will work.$('tableId tr').each(function (index, row){    if(row.childNodes[1].innerText == 'whatever'){        lastRow = $(row);                           row.childNodes[1].innerText = "New Value";}因此,我可以認為新創(chuàng)建的行在添加到 lastRow 時不是活動的 dom 元素,但不確定為什么或如何解決它。編輯:小提琴: https://codepen.io/josh-dredge/pen/ZEppyXm? editors=1111復制。按“添加普通行”。兩三次。按“添加指令行”。什么都不會發(fā)生(這是注定的)按“更新普通行”。第一個正常行將更新。4 按“添加指令行”?,F(xiàn)在將在更新的普通行之后添加指令行
查看完整描述

1 回答

?
達令說

TA貢獻1821條經(jīng)驗 獲得超6個贊

由于您的變量newRow是字符串,因此當您這樣做時:

$('#tableId').append(newRow);
lastRow = $(newRow);

它不是相同的“newRow” - 第二行通過重新解析字符串創(chuàng)建一個新元素(尚未附加到 DOM)。

相反,你可以這樣做:

lastRow = $(newRow);
$('#tableId').append(lastRow);

或者

lastRow = $(newRow).appendTo('#tableId')

兩者都將設(shè)置lastRow為已附加且位于 DOM 中的行


查看完整回答
反對 回復 2023-11-02
  • 1 回答
  • 0 關(guān)注
  • 207 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號