替换单元格内容Jquery

时间:2013-09-20 17:18:02

标签: jquery

如何替换链接所在的单元格内容并单击它?

<table>
<tr>
   <td>link here</td>
   <td>link here</td>
   <td>link here</td>
</tr>
</table>

例如,单击第二个单元格中的链接应替换第二个单元格内容test第三个链接替换第三个单元格,依此类推。基本上替换链接所在的单元格内容。

3 个答案:

答案 0 :(得分:4)

这样的事情:

$('table').on('click', 'a', function(event) {
  event.preventDefault();
  $(this).closest('td').html('test');
});

答案 1 :(得分:0)

我认为这就是你想要的:

$("td").click(function() {
    $(this).text("test");
});

答案 2 :(得分:0)

您必须将jQuery click事件分配给每个单元格:

$(document).ready(function {
    $("td").click(function() {
        $(this).html("test"); // Change the clicked cell content for test
    });
});
相关问题