我是 jQuery 的新手,我正在尝试编写一些代码来遍历页面并重写 anchor 链接 href 属性,以便删除空格并替换为 %20。
到目前为止我有:
$(".row a").each(function(){
$(this).attr("href").replace(/\s/g,"%20");
});
我已经尝试了一些变体,但没有成功。
最佳答案
您最好使用 native javascript encodeURI
功能。
$(".row a").each(function(){
$(this).attr( 'href', encodeURI( $(this).attr("href") ) );
});
关于javascript - jQuery/Javascript 将 anchor 链接中的 <space> 替换为 %20,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/853804/