日期:2014-05-16 浏览次数:20423 次
<table width="300" border="1"> <tr> <td>1 </td> <td>2 </td> <td>3 </td> <td><a href="deleteCurRow();">delete current row</a> </td> </tr> <tr> <td>11 </td> <td>22 </td> <td>33 </td> <td><a href="deleteCurRow();">delete current row</a> </td> </tr> <tr> <td>111 </td> <td>222 </td> <td>333 </td> <td><a href="deleteCurRow();">delete current row</a> </td> </tr> <tr> <td>1111 </td> <td>2222 </td> <td>3333 </td> <td><a href="deleteCurRow();">delete current row</a> </td> </tr> </table>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <table id="t" width="300" border="1"> <tr> <td>1111</td> <td>2222</td> <td>3333</td> <td><a href="javascript:void(0)" onclick="javascript:deleteCurRow(this);">delete current row</a></td> </tr> <tr> <td>1111</td> <td>2222</td> <td>3333</td> <td><a href="javascript:void(0)" onclick="javascript:deleteCurRow(this);">delete current row</a></td> </tr> <tr> <td>1111</td> <td>2222</td> <td>3333</td> <td><a href="javascript:void(0)" onclick="javascript:deleteCurRow(this);">delete current row</a></td> </tr> <tr> <td>1111</td> <td>2222</td> <td>3333</td> <td><a href="javascript:void(0)" onclick="javascript:deleteCurRow(this);">delete current row</a></td> </tr> </table> <script> function deleteCurRow(ele){ var t = document.getElementById('t'); var _parent = ele.parentNode.parentNode; t.getElementsByTagName('tbody')[0].removeChild(_parent); return false; }; </script> </td> </body> </html>
------解决方案--------------------
<table width="300" border="1"> <tr> <td>1 </td> <td>2 </td> <td>3 </td> <td><a href="#" onclick="deleteCurRow(event)">delete current row</a> </td> </tr> <tr> <td>11 </td>