有人知道当内容是 JC 时如何用 John 替换 td 标签的内容吗??? 尝试了一下,但无法让它完全发挥作用。
<body>
<table>
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
</tr>
<tr>
<td>PQ</td>
<td>ML</td>
<td>JC</td>
</tr>
</table>
<script>
$('td').filter(function () {
return $.trim($(this).text()) === "JC";
}).innerHTML.replace("JC","John");
<script>
</body>
最佳答案
只需使用包含:http://api.jquery.com/contains-selector/
$('td:contains("JC")').text("john");
关于javascript - 使用 td 元素中的 javascript 将特定内容替换为其他内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19940356/