문제

I have many database rows that used relative url with one directory up.

How do i change this relative url:

<a href="../somefolder"></a>

to

<a href="../additionalfolder/somefolder"></a>

FYI: I use jQuery 1.2.6

도움이 되었습니까?

해결책

Try

$('a').attr('href', function(_, href){
    return href.replace(/^\.\./, '../additionalfolder')
})

다른 팁

this might help you

var strUrl = window.location.protocol + "//" + window.location.host + "/";

this will give you the root folder path now you can concate your database path to this.

Hope this is the output you expect?

 $(function(){
   var $a =$('a');
     var OldUrl =   $a.attr('href');
     var newUrl = OldUrl.replace("../","../additionalfolder/");         
      $a.attr('href', newUrl);

});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top