更改表格单元格值jquery [英] change table cell value jquery
本文介绍了更改表格单元格值jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< table> 我需要找到一个包含特定文本值的表格单元格,并将其更改为其他内容。 < TR>
< td>你很好< / td>
< td>我讨厌你< / td>
< / tr>< / table>
找到包含我恨你的表格单元格,并将其改为我爱你。
我如何在Jquery中完成这项工作?
解决方案
code>:包含选择器:
$('td:contains(I hate你) ')文本(。' ......');
使用过滤器
方法:
$ $ $ $'$ c $ $''td')。filter(function(){
// contains
return $(this)。 indexOf(我讨厌你)> -1;
//完全匹配
//返回$(this).text()===我讨厌你;
})。text('...');
或者:
$('td')。text(function(i,text){
return text.replace('I hate you','我爱你!');
}) ;
I need to find a table cell that contains certain text value and change that to something else.
<table><tr>
<td>You are nice</td>
<td>I hate you</td>
</tr></table>
Find the table cell that contains "I hate you" and change that to "I love you".
How do I do that in Jquery?
解决方案
Using :contains
selector:
$('td:contains("I hate you")').text('....');
Using filter
method:
$('td').filter(function(){
// contains
return $(this).text().indexOf("I hate you") > -1;
// exact match
// return $(this).text() === "I hate you";
}).text('...');
Or:
$('td').text(function(i, text){
return text.replace('I hate you', 'I love you!');
});
这篇关于更改表格单元格值jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文