我試圖在點擊一個按鈕時刪除一行。它工作正常,除非我在一個表內。我的JSP在表中有50行的組合,之後我們嵌套這些表。現在,我的問題是如果我想刪除上一個表中的最後一行,我應該怎麼做?使用JavaScript刪除節點
我附上UI和調試器HTML視圖的屏幕截圖。任何建議都會有所幫助。
[DROW]這裏是我們有一個樹結構的不同行。我們需要首先爬到每一行,然後向下移動到lastChild以刪除最後一行。
這是唯一可能的,如果我的previousRow包含最後一行val。我無法理解它。
function removeAnotherResponse(arg0, data, response, request){
// Make sure the response has everything we need
if(arguments==null || arguments.length<4 || !request.content || request.content==null || !request.content.groupUniqueId || request.content.groupUniqueId==null){
return;
}
// Check for true response
if(!data || data==null || !data[0] || !data[0].removedSuccess || data[0].removedSuccess!=true){
return;
}
var groupUniqueId=request.content.groupUniqueId;
// Get the add another button row and add the new row before it.
var addAnotherRow=document.getElementById("ADD_"+groupUniqueId);
if(addAnotherRow==null) return;
var previousRow=document.getElementById("ADD_"+groupUniqueId).previousSibling;
addAnotherRow.parentNode.removeChild(previousRow);
showOrHideAddRemoveButtons(groupUniqueId, data[0].removeButton, data[0].addButton);
updateSectionCount(groupUniqueId, false);
getPortCount(groupUniqueId);
}
添加代碼不是截圖。 – Mritunjay 2014-08-31 13:02:10
@Mritunjay ..我添加了我用來刪除表內行的代碼。我無法移動到上面嵌套了表格的行,如調試屏幕截圖所示。 – Bhaskar 2014-08-31 13:05:41
'id'屬性值應該是每個元素唯一的。在這裏你應該使用不具有相同值的'id'類。 – GillesC 2014-08-31 13:14:16