更改标签值

Dev*_*per 1 html javascript jquery

任何线索,我怎么能访问每个thclass="CenteredHeader"通过jQuery添加更多的参数a标签?

<tr class="CenteredHeader">
  <th scope="col"></th>
  <th scope="col">
      <a href="/BoxOffice/Movies/807?sort=MovieName&amp;sortdir=ASC">Pelicula</a>
  </th>
  <th scope="col">
      <a href="/BoxOffice/Movies/807?sort=TechnologyName&amp;sortdir=DESC">Tecnologia</a>
  </th>
</tr>
Run Code Online (Sandbox Code Playgroud)

the*_*dox 8

$('.CenteredHeader th a').each(function() {
    $(this).attr('href', function(i, oldhref) {
         return oldhref + '&amp;p1=111'
     });
})?;
Run Code Online (Sandbox Code Playgroud)

如果需要,可以a通过上述解决方案对每个标记使用不同的参数.

也可以像@FrançoisWahl评论所述:

$('.CenteredHeader th a').attr('href', function(i, oldhref) {
     return oldhref + '&amp;p1=111'
})?;
Run Code Online (Sandbox Code Playgroud)

  • @LiviuT. - 版本1.1及以上.(所以_almost_任何版本.)你可以用其他方法做同样的事情,如`.html()`,`.text()`和`.val()`. (2认同)