用不同的文本更改课堂上的文本

Change text in class with deferent text

本文关键字:文本 课堂      更新时间:2023-09-26

使用jQuery是否可以在具有相同类的每个节点的末尾添加不同的单词?

例如:

<p class="xyz">Some text</p>
<p class="xyz">Some another text</p>
<p class="xyz">Text somewhere</p>

那么将是:

<p class="xyz">Some text word1</p>
<p class="xyz">Some another text word2</p>
<p class="xyz">Text somewhere word3</p>

感谢

使用:

$('.xyz').each(function(i){
    $(this).html($(this).html()+" word"+(i+1));//or  $(this).text($(this).text()+" word"+(i+1));
});

工作演示

看看这个:

$('.xyz').each(function(i){
  var count = i+1;
  $(this).html($(this).html()+ "word" + count)
});

http://jsfiddle.net/y9043kdn/1/