开发者

change href jquery

On a search results page I have links. I would like to change the href of certain href from DispForm.aspx?ID=n to 开发者_运维问答AllItems.aspx?ID=n but just for the href that have /R/I/P/ in the url.

I would like to use jQuery to change those href. Any suggestions?

<a title="" href="http://win/R/I/P/IL/F/DispForm.aspx?ID=n" id="S">link one</a>
<a title="" href="http://win/R/I/P/L/PN/DispForm.aspx?ID=n" id="S">link two</a>
<a title="" href="http://win/L/L/DispForm.aspx?ID=n" id="S">link three</a>


jQuery('a[href*="/R/I/P/"]').each(function(){
    this.href = this.href.replace('DispForm', 'AllItems');
});


With this:

$("a[href*='/R/I/P/']").each(function(){
   var href = $(this).attr('href').replace('DispForm.aspx?', 'AllItems.aspx?');
   $(this).attr("href", href);
});


this should do it!

http://jsfiddle.net/2VZMb/


$('a').each(function() {
var href = $(this).attr('href');
if (href.indexOf("/R/I/P") >= 0) {
  $(this).attr('href', new_href);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜