开发者

Basic JQuery: Replace a link string with another

How do I change:

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

to

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

using Jquery?

I have the following code and would like to change it in the event of a right click: (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;
    }
  });
});


Is this what your looking for?

...
case 2:
   var href = $(this).attr("href").replace(/event/g, "contest")
   // do stuff with href


"http://test.dev/event?event=94&page=4".replace(/event/g,'contest');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜