开发者

Append string to child link URLs

开发者 https://www.devze.com 2023-01-28 07:18 出处:网络
What\'s the best way to append a string to the end of links in a list with Javascript? From: <div id=\"pagination\">

What's the best way to append a string to the end of links in a list with Javascript? From:

<div id="pagination">
  <ul>
    <li><a href="http://site.com/P1/">Page 1</a></li>
    <li><a href="http://site.com/P2/">Page 2</a></li>
  </ul>
</div>

to

<div id="pagination">
  <ul>
    <li><a href="http://site.com/P1/?some=blah">Page 1</a></li>
    <li><a href="http://site.com/P2/?some=blah">Page 2</a></li>
  </ul>
</div>

ExpressionEngine gives litt开发者_如何学Gole control to how these pagination links are generated.


$('#pagination a').attr('href', function() {
  return this.href + '?some=blah';
});

Look at it working here.

Edited as per elusive's input in the comments.


Quick and dirty:

$('#pagination li a').each(function() {
    this.href += '?some=blah';
});


This should work for you:

$('#pagination a').each(function () {
    this.href += '?some=blah';
});

Change #pagination a to whatever selector you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号