jQuery替换ID中包含字符串的元素的所有文本 [英] JQuery replace all text for element containing string in id

查看:391
本文介绍了jQuery替换ID中包含字符串的元素的所有文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试选择页面上所有具有字符串"aggr"作为其id值一部分的元素.然后,我尝试将这些元素中的文本求和"替换为总计".

I am trying to select all elements on the page which have the string 'aggr' as part of their id value. Then I am trying to replace the text 'Sum 'in these elements to 'Total'.

我的JQuery在下面,但似乎不起作用....

My JQuery is below but doesn't seem to be working....

$('TBODY[id*=aggr]').each(function(i){
var aggrHTML = $('TBODY[id*=aggr]');
          var aggrText = aggrHTML.text();
          var newText = aggrText.replace("Sum","Total Holiday Leave")
         aggrHTML.html(newText);
});

推荐答案

尝试一下:

$('TBODY[id*=aggr]').each(function(i){
  $(this).html($(this).html().replace("Sum","Total Holiday Leave"));
});

这篇关于jQuery替换ID中包含字符串的元素的所有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆