开发者

Jquery url replace

开发者 https://www.devze.com 2022-12-09 14:11 出处:网络
How can I modify this: /services/typ开发者_StackOverflow社区e/single_dwelling/ to this: /ajax/services/single_dwelling/development

How can I modify this:

/services/typ开发者_StackOverflow社区e/single_dwelling/

to this:

/ajax/services/single_dwelling/development

Currently I have:

linkUrl = $(this).attr("href").replace(/(\/(services)\/)/,"$1ajax/");

Which outputs:

/services/ajax/type/single_dwelling/

I'm a little confused.


Looking carefully I see you want to prepend '/ajax', remove '/type' from the original url, and append 'development':

var linkUrl = '/ajax' + $(this).attr("href").replace('type/','') + 'development';

That will output "/ajax/services/single_dwelling/development" using your test string.


Try:

linkUrl = "/ajax" + $(this).attr("href").replace("/type", "") + "development";
0

精彩评论

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