jQuery / Javascript replace in anchor link with

后端 未结 6 1546
独厮守ぢ
独厮守ぢ 2021-01-04 23:49

I\'m new to jQuery and i\'m trying to write some code to go through the page and rewrite anchor links href attribute so that spaces are removed and replaced with %20.

<
6条回答
  •  星月不相逢
    2021-01-05 00:09

    You have to set the attribute value ( attr(key, value) ), in your code you are only reading its value:

    $(".row a").each(function(){
      $(this).attr('href', $(this).attr("href").replace(/\s/g,"%20"));
    });
    

提交回复
热议问题