如何使用Jquery从波纹管表格单元格中删除“def”。
<table>
<tr>
<td>abc def</td>
<td>xyz def</td>
<td>lmn def</td>
</tr>
<tr>
<td>def</td>
<td>abc def</td>
<td>xyz def</td>
</tr>
</table>
答案 0 :(得分:5)
修改强> 你可以这样做:
$("td:contains(def)").each(function(){
var newText = $(this).text().replace(/def/g, "");
$(this).text(newText);
});
希望这会有所帮助。干杯
答案 1 :(得分:2)
您可以使用:contains()选择器并将函数传递给text()方法:
$("td:contains(def)").text(function(index, currentText) {
return currentText.replace("def", "");
});