2012-05-03 91 views
0
<td><input type="button" value="remove" onClick="removeBox(this.parentNode.parentNode.rowIndex); "/></td> 

function removeBox(i) 
     { 
      document.getElementById("firstTbl").deleteRow(i); 

     } 

我這個代碼工作,我可以刪除刪除文字我的整個TR,但是當我想在我的鏈接比它不工作讓我解釋一下,當我想應該有相同的功能與名稱的鏈接刪除的用戶點擊,從而強調其鏈接刪除文本我的意思是像我以前的工作,整個TR唯一的區別是,我用的onclick按鈕現在是在錨標記通過的onclick應用錨標記

<td><a href="#" onclick="removeLink(this.parentNode.parentNode.rowIndex);">Remove</a></td> 
function removeLink(i) 
{ 
document.getElementByID('tab2').deleteRow(i); 

} 

上面有是我的代碼,這是不一樣的錨定標記

+2

你應該張貼的工作和非工作職能的jsfiddle,所以我們可以看到它到底應該如何工作。 – gcochard

+1

請使用http://jsfiddle.net:很難確切地看到你想要做什麼。 –

回答

0

我強烈建議你點擊返回false以阻止頁面被重新加載或部分卸載。

<td><a href="#" onclick="return removeLink(this.parentNode.parentNode.rowIndex);">Remove</a></td> 
function removeLink(i) { 
    document.getElementByID('tab2').deleteRow(i); 
    return false 
} 
+0

它會工作嗎? –

+0

你可以試試嗎? – mplungjan

2

您不應該使用內聯事件。這是舊式的。

<a href="#" class="remove">Remove</a> 

而在JS中用jQuery;

$('.remove').on('click', function (e) { 
    e.preventDefault(); 

    $(this).closest('tr').remove(); // will delete the upper tr. 
});