开发者

Using jQuery, help modifying a set of urls

I am getting a selection of URLs using:

$("a.someclass")

Now my urls look like:

http://www....com/something/12321

I need to modify the urls by removing the trailing num开发者_开发问答ber to become:

http://www....com/something/

How can I do this?


Something like this might work, using a regexp to remove the trailing number:

$("a.someclass").each(function() {
  $(this).attr('href', function(index, attr) {
    return attr.replace(/^(.*)\d+$/, '$1');
  });
});


You could do this if the href actually ends with a number:

$("a.someclass").attr('href',function(i,href){return href.replace(/\d+$/,'');});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜