我需要找到一个包含特定文本值的表格单元格并将其更改为其他值。
<table><tr>
<td>You are nice</td>
<td>I hate you</td>
</tr></table>
找到包含“我恨你”的表格单元格并将其更改为“我爱你”。
我如何在 Jquery 中做到这一点?
最佳答案
使用 :contains
选择器:
$('td:contains("I hate you")').text('....');
使用filter
方法:
$('td').filter(function(){
// contains
return $(this).text().indexOf("I hate you") > -1;
// exact match
// return $(this).text() === "I hate you";
}).text('...');
或者:
$('td').text(function(i, text){
return text.replace('I hate you', 'I love you!');
});
关于javascript - 更改表格单元格值jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14763148/