2012-01-26 10 views
1

私はテーブルがあるページを持っています。テーブルにはアンカーを含む要素が含まれています。JavaScriptを使用してアンカーを更新する

それは、このように余分なクエリ文字列パラメータを持つように私は何をしたいことはアンカーの更新です
<th scope="col"> 
<a href="/Admin/Auction/Closed?sort=InventoryReference&sordir=ASC&sortdir=DESC">Inventory reference</a> 
</th> 

<th scope="col"> 
<a href="/Admin/Auction/Closed?sort=InventoryReference&sordir=ASC&sortdir=DESC&page=3">Inventory reference</a> 
</th> 

、私は今、私がしなければならないことをこれは、ように見える番目の何例ですこれを行う:

<script language="javascript" type="text/javascript"> 

    $(document).ready(function() { 
     $('th[scope^=col]') ??? 
    }) 

</script> 

問題は、私は何を置き換えるべきか分からない。誰にも分かりますか?私はアンカーをつかんで余分なクエリ文字列パラメータを追加するJavaScriptまたはJQueryコードが必要だと思っています。問題は、コードが正確にどうなるでしょうか?あなたは、URLが既にクエリ文字列にpageのparamを含めることができると思うと、あなたはこのコードを使用し、その値を更新する必要がある場合は

おかげで、

サチン

答えて

3

これを試してみてください:

$(document).ready(function(){ 

    $('th[scope^=col]').each(function(){ 

     var old_link = ""; 
     var new_link = ""; 
     //Get the current href value of the child anchor tag of 'th[scope^=col]' 
     old_link = $(this).children('a').attr('href'); 
     //Append the extra string required '(in this case &page=3)' to the old_link 
     new_link = old_link + '&page=3'; 
     //Set the href value for the anchor tag within 'th[scope^=col]' 
     $(this).children('a').attr('href',new_link); 

    }); 

}); 

は、この情報がお役に立てば幸いです。

+0

ありがとうSagar - それは上にあった。私は許可されているときにこの回答を6分で受け入れる。 –

+0

あなたがこのコードを行ごとに説明できるかどうか:-) –

+0

これには少しの問題があります:最初のデータからのすべてのリンクが更新されます。 –

3

この

$(document).ready(function() { 
    $('th[scope=col] a')[0].href += "&page=3"; 
}); 

を試してみてください。

$(document).ready(function() { 
    $a[0].href = $a[0].href.replace(/([?&])page=[^&]*&?/,'$1') + '&page=3'; 
}); 
+0

私は.. href'は、jQueryのメソッドであること ' –

+0

@RobWを思い出すことができない - 私は推測する私の心の外でした、ありがとう: – ShankarSangoli

+0

- のために今 –

1
$(document).ready(function() { 
    $('th[scope=col] a').each(function(){ 
     $this = $(this); 
     $this.attr('href', $this.attr('href') + '&page=3'); 
    }); 
});