2011-06-23 6 views
0

とのリンク文字列を交換してはどうすれば変更できますか:基本はJQuery:別の

http://test.dev/event?event=94&page=4

のjQueryを使用して

http://test.dev/contest?contest=94&page=4

に?

私は、次のコードを持って、右クリックした場合にそれを変更したいと思います:(CASE 2)

// will_paginate + ajax 
// updates two divs: #pages and #pagelink 
// see places#search controller; passes 4 parameters to the search action 

$(function(){ 
    $('.pagination a').mousedown(function(event) { 
     switch (event.which) { 
      case 1: 
       $(".pagination a").live("click", function(event) { 
       event.preventDefault(); 

       // Javascript Regular expression function; extracts page number from full url 
       var extractPageNumber = function(s) { 
       var r=/page=(\d+)/, m=(""+s).match(r); 
       return (m) ? Number(m[1]) : undefined; 
       }; 
       var pageregex = extractPageNumber($(this).attr('href')); 
       $(".pagination").html("Page is loading...") 
       $.get("/event", { event: $("input[name=event]").val(), page: pageregex }, function(data) { 
       $('#pagelink').html(data.page_link); 
       console.log(data.page_link); 
       $('#tweets').html(data.html); 
       }); 
       return false; 
       }); 
      break; 

      case 2: 
       break; 
    } 
    }); 
}); 
+0

は、単純な "イベント" となっていますか?また、誰かが通常リンクをクリックすると(右クリックするのではなく)、どうなりますか? – mc10

+0

通常のクリックが発生した場合、JQueryを使用してサーバーからJSON要素を取得します。これは$( '#tweets').html(data.html)を使用してJSONからページ要素を更新します。右クリックは、JSONを返さない別のURLを取得するために使用されます。 –

答えて

1

は、あなたが探して何本か?許容> "コンテスト" 文字列置換 -

... 
case 2: 
    var href = $(this).attr("href").replace(/event/g, "contest") 
    // do stuff with href 
0
"http://test.dev/event?event=94&page=4".replace(/event/g,'contest');